WordPress Hack | Set Class for Home Page Link
Posted by admin | Filed Under Blog, Cool Stuff | August 19, 2008
The Problem:
Needed the home page button status to appear active, or in WP terms, as the “current_page_item”. So I need to determine if the page I was on was the home page or not, and if it was, I needed to add a class to it of “current_page_item”.
Solution:
Just a little PHP script does the trick- added into the LI element.
<ul>
<li <?php if (is_home())
echo ‘class=”current_page_item”‘;?>><a href=”<?php echo get_settings(‘home’); ?>/”>Home</a></li>
<?php wp_list_pages(’sort_column=menu_order&depth=1&title_li=’);?>
</ul>
That’s it!
NOTE: Here is a useful plugin to check out and that I am using with the code above: Current-Page-Bugfix
Feedback
Got something to say?














