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
Joe Bruno
35,909 PointsPHP strip_tags + Wordpress Menu
Hello,
The code below outputs a wordpress menu, from which I am stripping the tags, but leaving the <a> tags; however, I want to add <li> tags before EACH <a> tag. The code below is not looping over each <a> tag (I know I have not told it too. I am a newbie to php and cannot find some type of "each" function ). It has simply added one <li> before the menu and a closing </li> after. I could use jQuery to add the html tags, but I would think this could be better accomplished, given the situation below, with less code using PHP? Thanks in advance.
<nav>
<ul>
<?php
$args = array(
'menu' => 'mainMenu',
'echo' => false,
);
echo '<li>', strip_tags(wp_nav_menu( $args ), '<a>'), '</li>';
?>
</ul>
</nav>
1 Answer
Isaac Dozier
882 PointsUse a foreach() command maybe?
ex.
<?php foreach ($args as $arg) { 'echo results here' } ?>