Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Coding the Header and Footer Templates: wp_nav_menu issues

I am right in the middle of creating a wordpress theme for a local church and I seem to be having an issue where the function echo strip_slashes(wp_nav_menu($args), '<a>'); returns my menu back with the first item not linked correctly... I end up with code that looks similar to this...

<div class="span8&gt; &lt;a href=" http:="" localhost="" theagapechurch.tv=""     contact="" "="">Contact
<a href="http://localhost/theagapechurch.tv/learn/">Learn</a>
<a href="http://localhost/theagapechurch.tv/sermons/">Sermons</a>
<a href="http://localhost/theagapechurch.tv/connect/">Connect</a>
<a href="https://agapechurch.cloverdonations.com/a-giving/">Give</a>
</div>

the $args for wp_nav_menu are as follows:

<?php
$args = array(
'menu' => 'main-menu',
'echo' => false
);
echo strip_tags(wp_nav_menu($args), '<a>);
?>

I am completely lost on this and would greatly appreciate some input. Thanks!

1 Answer

I'm not entirely sure why, but the source of the problem was the <nav> container. For some odd reason my code wasn't picking up that there was a </nav> at the bottom. So at that point the <nav> container was open ended which threw the menu off.

Anyway, here is that whole bit of code with the div and nav containers that are working...

<div class="grid_8">
<nav>
<?php 
$args = array(              
'menu' => 'main-navigation',
'echo'=> false
); 

echo strip_tags (wp_nav_menu($args), '<a>');
?>
</nav>
</div>