Support » Fixing WordPress » wp_nav_menu after, before not working

  • Resolved JoeGCh

    (@joegch)


    Site is at joechilds.co.uk (working on converting a design to a WP theme).

    I’m trying to use wp_nav_menu() to show a nav menu at the top of the site. I have 4 pages, and it’s getting them fine, no problems at all.

    If I use
    <?php wp_nav_menu(); ?>
    it shows

    <div class="menu">
    <ul>
    	<li class="page_item page-item-39"><a href="http://site/code/" title="Code">Code</a>
    	<li class="page_item page-item-41"><a href="http://site/work/" title="Work">Work</a>
    	<li class="page_item page-item-43"><a href="http://site/resume/" title="Resume">Resume</a>
    	<li class="page_item page-item-45"><a href="http://site/contact/" title="Contact">Contact</a>
    </ul>
    </div>

    [Code][Work][Resume][Contact]
    [ ] denotes the link

    If I use
    <?php wp_nav_menu(array('link_after' => '-')); ?>
    it shows

    <div class="menu">
    <ul>
    	<li class="page_item page-item-39"><a href="http://site/code/" title="Code">Code-</a>
    	<li class="page_item page-item-41"><a href="http://site/work/" title="Work">Work-</a>
    	<li class="page_item page-item-43"><a href="http://site/resume/" title="Resume">Resume-</a>
    	<li class="page_item page-item-45"><a href="http://site/contact/" title="Contact">Contact-</a>
    </ul>
    </div>

    [Code-][Work-][Resume-][Contact-]
    [ ] denotes the link

    If I use
    <?php wp_nav_menu(array('after' => '-')); ?>
    it shows

    <div class="menu">
    <ul>
    	<li class="page_item page-item-39"><a href="http://site/code/" title="Code">Code</a>
    	<li class="page_item page-item-41"><a href="http://site/work/" title="Work">Work</a>
    	<li class="page_item page-item-43"><a href="http://site/resume/" title="Resume">Resume</a>
    	<li class="page_item page-item-45"><a href="http://site/contact/" title="Contact">Contact</a>
    </ul>
    </div>

    [Code][Work][Resume][Contact]
    [ ] denotes the link

    The last example, as I understand it, should show
    [Code]-[Work]-[Resume]-[Contact]-
    which is what I want, but can’t get.

    Any ideas?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Still not found a solution, although I thought I may just go and extend the wp_nav_menu method to take a separator parameter, as splitting the return string to remove the last separator would be a little more hassle, I think.

    What’s the proper way to go about extending a core method in WP?

    Finally getting somwhere. It seems that it’s not actually calling wp_nav_menu because it’s not being able to find a menu to use, so it’s falling back to wp_page_menu which doesn’t accept an ‘after’ parameter.

    Currently trying to find out how to make a menu that it can recognise, so it can use wp_nav_menu().

    ————

    Edit: OK, got that. Now just to work on removing the last ‘-‘ from the menu that I didn’t want. Good old 80/20.

    Could you please reveal how did you fixed the wp_nav_menu(), so that it shows the separator ‘after’ correctly?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_nav_menu after, before not working’ is closed to new replies.