While designing custom navigations, custom page templates, custom sidebar elements you may need to test current page. Here is a simple trick for getting current page.

The trick is using page slug inside is_page function. For example on your “About” page you can use:

<?php if(is_page('about')){ ?>

Put some HTML code here for About page.

<?php } ?>

This code tests if the current page is about page, and it will show the code in between if is_page returns true.

You can also create a simple function to echo “current” class for the current page using this function:


function stf_is_current($slug){ if(is_page($slug)){ return " current"; } }

  // Sample link
  echo '<li><a href="https://wpassist.me/contact" class="'.stf_is_current('contact').'">Contact</a></li>';


This code will output the link to contact page with current class on Contact page only. You can use this simple trick on your custom navigation templates. It is generally used for styling current page link.

I hope you found it useful.

Deal Notice: We are using A2 hosting for all of our websites, and we are really happy with their service. So we wanted to share you this discount link for you to try it out. If you get a hosting using this link, you will also help us build better content for you: SSD Hosting - 300% Faster Than Standard Hard Drives