[resolved] Add Link to Nav (5 posts)

  1. Fedge
    Posted 3 years ago #

    I want to add a link to the end of the main (top) navigation regardless of which template is being used or how the menus get configured. It would be nice if I could get it treated the same as all the other nav links (templating treats it like a page). I don't want to use WP's database because the link needs to be displayed only sometimes based on data from other sources. I've found hooks to add content to lots of parts of the page but so far I've only found a function that retrieves this menu, nothing that injects a link.

  2. Is your theme using the Appearance > Menus system?

  3. Fedge
    Posted 3 years ago #

    I need this to work regardless of the theme. I'm writing a plugin. I guess I should have specified that, sorry.

  4. For custom menus you can use something like this:

    function pw_custom_nav_menu_items($items, $args) {
    	$items .= '<li class="menu-item"><a href="#">Your Link Here</a></li>';
        return $items;
    add_filter( 'wp_nav_menu_items', 'pw_custom_nav_menu_items', 10, 2 );

    Menus outputted with wp_pages_menu() is a bit different, so I'd advise you look at the source: http://core.trac.wordpress.org/browser/tags/3.4.1/wp-includes/post-template.php#L885

  5. Fedge
    Posted 3 years ago #

    Ahh it's in the filters! Thanks a bunch!

Topic Closed

This topic has been closed to new replies.

About this Topic