Issue adding [language-switcher] in navigation block
-
Hello,
Prior to the last WP security update (6.1.3), I managed to add TranslatePress language switcher shortcode inside navigation block in FSE themes as a custom link by just inserting [language-switcher] and it worked perfectly. Unfortunately, it stopped to work since 6.1.3 security update and it’s still not working after 6.2.2.
I noticed that it’s a plugin block available called Language Switcher, but it’s not allowed inside the navigation block. Any plans to allow this block inside the navigation block in a future version of this plugin? Or the plugin can’t make this change, only the WordPress team?
After some research, I managed to create the following function that changes the content of the nav menu item to run the language switcher block (also tried run the shortcode and the result is the same), it works but it is exposing the script code as text node in the front-end of the website. I tried to remove it or move it into a script tag using JavaScript, but it still flashes when page is loading. Not an ideal solution ??
function add_lang_switcher_in_menu( $items ) { foreach ($items as $item) { if ( $item->parsed_block['attrs']['className'] === 'language-switcher' ) { $lang_switcher_block = '<!-- wp:trp/language-switcher /-->'; $item->parsed_block["attrs"]["label"] = do_blocks( $lang_switcher_block ); } } return $items; } add_filter('block_core_navigation_render_inner_blocks','add_lang_switcher_in_menu');
Any suggestions on how to solve this issue will be much appreciated.
Thanks!
- The topic ‘Issue adding [language-switcher] in navigation block’ is closed to new replies.