夏期劇場
夏期劇場

Reputation: 18327

Wordpress how to replace the Strings/URLs in "wp_nav_menu" output or %3$s thing?

I'm currently using something like:

wp_nav_menu( array(
               'theme_location' => 'primary', 
               'container' => false, 
               'items_wrap' => '<ul id="primary-main-menu" class="primary-main-menu-en">%3$s</ul>',
               'fallback_cb' => false
));

Then i got a pretty decorated menu with my own class, etc.
But now another more tricky step is:

Note:
I used walker but i could not use walker altogether with items_wrap option and/or the output is something distorted. So i gave up walker. Any sharp idea please?

Upvotes: 2

Views: 2639

Answers (1)

kjetilh
kjetilh

Reputation: 4976

Instead of defining your own Walker class you can simply hook into the default Walker using the filter walker_nav_menu_start_el. Here you can modify the link HTML before it's outputted.

Below is a working example of your use-case:

function mytheme_walk_nav_menu_items($output, $item, $depth, $args) {

    if ( $args['theme_location'] === 'primary' ) {
        $output = str_replace( 'www.domain1.com', 'www.domain2.com', $output );
    }

    return $output;
}
add_filter( 'walker_nav_menu_start_el', 'mytheme_walk_nav_menu_items', 10, 4 );

Upvotes: 3

Related Questions