diff --git a/mu-plugins/blocks/global-header-footer/blocks.php b/mu-plugins/blocks/global-header-footer/blocks.php index a32d275cd..11532f72a 100644 --- a/mu-plugins/blocks/global-header-footer/blocks.php +++ b/mu-plugins/blocks/global-header-footer/blocks.php @@ -14,6 +14,7 @@ add_action( 'wp_head', __NAMESPACE__ . '\preload_google_fonts' ); add_filter( 'style_loader_src', __NAMESPACE__ . '\update_google_fonts_url', 10, 2 ); add_filter( 'render_block_core/navigation-link', __NAMESPACE__ . '\swap_submenu_arrow_svg' ); +add_filter( 'render_block_core/search', __NAMESPACE__ . '\swap_header_search_action', 10, 2 ); /** * Register block types @@ -1044,3 +1045,22 @@ function( $val, $key ) use ( &$urls ) { function swap_submenu_arrow_svg( $block_content ) { return str_replace( block_core_navigation_link_render_submenu_icon(), "", $block_content ); } + +/** + * Replace the search action url with the custom attribute. + * + * @param string $block_content The block content about to be appended. + * @param array $block The block details. + * @return string The filtered block content. + */ +function swap_header_search_action( $block_content, $block ) { + if ( ! empty( $block['attrs']['formAction'] ) ) { + $block_content = str_replace( + 'action="' . esc_url( home_url('/') ) . '"', + 'action="' . esc_url( $block['attrs']['formAction'] ) . '"', + $block_content + ); + } + + return $block_content; +} diff --git a/mu-plugins/blocks/global-header-footer/header.php b/mu-plugins/blocks/global-header-footer/header.php index 47839d311..a2c2b23a3 100644 --- a/mu-plugins/blocks/global-header-footer/header.php +++ b/mu-plugins/blocks/global-header-footer/header.php @@ -98,43 +98,7 @@