How can I highlight the current WP page using this code:
<div id="menu">
<ul>
<li>
<?php wp_list_pages('title_li=&depth=1&exclude=52'); ?>
</li>
</ul>
</div>
How can I highlight the current WP page using this code:
<div id="menu">
<ul>
<li>
<?php wp_list_pages('title_li=&depth=1&exclude=52'); ?>
</li>
</ul>
</div>
Found in the (huge) documentation for wp_list_pages()
:
All list items (
li
) generated bywp_list_pages()
are marked with the classpage_item
. Whenwp_list_pages()
is called while displaying a Page, the list item for that Page is given the additional classcurrent_page_item
.
So use the current_page_item
class.
Yeah I tried that, but it's not working. Which led me to believe maybe I should use some code?
You can try and pass it the echo=0
parameter. It should return the HTML instead of printing it and you can process it to find the current page, apply the class and print the result. Not very clean, but if the normal behaviour doesn't work, it gives you a workaround.
The CSS needed; change color to whatever you want:
#menu ul li a:active, #menu ul li.current_page_item a
{
color:#000;
}