Tutorial – WordPress highlight the current page

This is great about WordPress! Everytime I can’t work something out it turns out alot of other people have had the same problem! Such as – “How To Highlight The Current Page In WordPress”

http://www.vanseodesign.com/wordpress/hightlight-current-page-wordpress/

Also got the code off VinnyPanico on twitter – http://codex.wordpress.org/Dynamic_Menu_Highlighting

<?php if (is_home()) { echo ” id=\”current\””; } ?>

so it gose in the code like this:

<div id=”main-nav”>
<?php if (is_home()) { echo ” id=\”current\””; } ?><?php wp_list_pages(‘title_li=’); ?>
</div>

and when you load up the page and view the source:

<div class="menu"><ul><li id="current_page_item"><a href="http://URL-HERE" title="blog">blog</a></li>

or if you want a home button it could look like this

<div id=”main-nav”>
<ul>
<?php wp_page_menu( array( ‘show_home’ => ‘blog’, ‘sort_column’ => ‘menu_order’ ) ); ?>
</ul>
</div>

The tag “wp_page_menu” also highlights the current page and when you load up the page and view the source:

<div class="menu"><ul><li class="current_page_item"><a href="http:URL-HERE" title="blog">blog</a></li>

The main issue I have is keeping everything flexible so that CMS uses can change and add without breaking the website.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s