ThemeShaper Forums » Thematic

[closed]

external menu link showing on all subpages

(6 posts)
  • Started 9 years ago by jrobben
  • Latest reply from neonbible
  • This topic is resolved
  1. I added an external link to my main menu. works great, but the link also shows on all submenus too. I need to restrict the menu link to the main menu only I am using this code in functions.php

    <?php //adds link to an external page to the main menu
    function child_add_menu_items($output) {
    	$my_code = '<li><a href="http://www.besthealthsupplies.com/magento/"target="blank">Store</a></li></ul>';
    	return str_replace('</ul>',$my_code, $output);
    
    	}	
    
    add_filter('wp_page_menu','child_add_menu_items');
    
    	?>

    this is the site where you can see the problem on the dropdown menus under "About" on www.besthealthsupplies.com. There should not be a link to Store on the dropdown child pages.

    Posted 9 years ago #
  2. Hi jrobben-

    The problem is str_replace is going to replace every instance of </ul>

    SInce we know how wp_page_menu outputs, it'd be better to search for a more specific string.
    Try:

    function child_add_menu_items($output) {
    	$my_search='</ul></div>';
    	$my_replecement = '<li><a href="http://www.besthealthsupplies.com/magento/"target="blank">Store</a></li></ul></div>';
    	return str_replace($my_search, $my_replecement, $output);
    	}	
    
    add_filter('wp_page_menu','child_add_menu_items');

    -Gene

    Posted 9 years ago #
  3. Thanks, it worked like a charm. Changing status to resolved.

    I tried a couple of things with a similar thought, but missed adding the </div> as the break point. I always have problems with menu dropdowns, as it is difficult targeting them with firebug.

    Posted 9 years ago #
  4. neonbible
    Member

    This works great. Is it possible to change the menu order? I am mixing page and external links.

    Posted 8 years ago #
  5. Yes but if you are going that far with it why not use the WP 3.0 Nav Menu function?

    Look here: http://forums.themeshaper.com/topic/thematic-menus-demystified-1

    Posted 8 years ago #
  6. neonbible
    Member

    Thats an awesome thread! Thanks.

    Posted 8 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.