• I have a menu top level item that I want all sub items to open in a new window.

    I guess this will need a php check if menu item == “abc” then add target=”_blank” to the url … and i guess this will go in header.php in my child theme ?
    This is just a guess. I can edit code but I’m not a true coder, I’m still learning!

    I see this code from dev menu help but I don’t know how to use it for my needs

    function wpdocs_special_nav_class( $classes, $item ) {
        if ( is_single() && 'Blog' == $item->title ) {
            $classes[] = "special-class";
        }
        return $classes;
    }
    add_filter( 'nav_menu_css_class' , 'wpdocs_special_nav_class' , 10, 2 );
Viewing 4 replies - 1 through 4 (of 4 total)
  • Yes, adding target blank will cause a link to go to a new window.

    Where you can find this may be different for different themes.. Usually its the header.php or menu.php, rarely it can be a sidebar.php.. I’ve had that once.. Took me 3 days to figure that out lol

    Thread Starter DanielKYantis

    (@danielkyantis)

    I found this in my header.php and I think I should add a function here:

    <nav class="navbar-collapse bs-navbar-collapse collapse" role="navigation" id="site-navigation">
    	<?php wp_nav_menu(
    		array(
    			'theme_location' 	=> 'primary',
    			'container' 		=> false,
    			'menu_class' 		=> 'nav navbar-nav navbar-right responsive-nav main-nav-list',
    			'fallback_cb'     	=> 'zerif_wp_page_menu'
    		        )
    	        );
    	?>
    </nav>

    PLEASE FEEL FREE TO TELL ME EXACTLY HOW TO IMPLEMENT

    Thread Starter DanielKYantis

    (@danielkyantis)

    After getting impatient waiting on some input, I found a plugin that makes all external links open in new window. It works.

    I would rather have done it in the header.php for only 1 menu that contains a bunch of links to an external site, but this does work.

    Hi Daniel,

    It might be a bit late, but if you go to Appearance > Menus and then click the the Screen Options on the top you have an option to display the target for each menu item.

    No need to adjust the code.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘nav menu – all sub items add target="_blank"’ is closed to new replies.