Highlight current page in Wordpress

What's the easiest way to highlight the current page from the navigation menu in Wordpress?

+2


source to share


3 answers


If your top navigation links are manually inserted into your theme, you can do something like this:

<a href="page-link" <?php if(is_page('page-name') : ?>class="highlight"<?php endif; ?> >Link text</a>

      

I am doing something like this in a theme where certain pages and categories have special titles. There are several conditional functions that help with this:



  • is_page ('page name')
  • is_category ('category name')
  • is_home ()
  • is_front_page ()

Edit: Didn't see any comments that these are WP dynamic links. You should still be able to use these functions if the request data you receive contains page pools.

Instead, you can use the get_pages () function and loop through it manually, performing an is_page () check on each of them to see if the current page id matches the page id you are on in the array.

+3


source


The highlighting of the current page sometimes depends on whether it will be implemented in the CSS of the theme you are using, but this should work in the main theme.

<?php wp_list_pages('title_li=&depth=1&'.$page_sort.'&'.$pages_to_exclude)?>



CSS: Change the color in CSS to something that stands out well against the background of the menu bar or background image. Change # to the container of the above list pages.

#menu ul li a:active, #menu ul li.current_page_item a
{
color:#000;
}

      

0


source


You can use the dtabs plugin , which does exactly this, for pages, categories, home, and other types of pages.

0


source







All Articles