Conditional Tags and WordPress

The thing I like the most about working with WordPress is its ability to do everything and anything you need it to. When designing a theme, or when using a a pre-made theme, WordPress offers quite a few conditional tags to help customize its look and feel to suit whatever your needs may be.
Conditional tags are used within PHP to state that you want something to happen only “if” something else happens first. For coders this is known as an “if” statement as well.

So for example, the conditional I use the most is the is_home() tag.
Here is what it would look like.


Now of course, the above code doesn’t do anything that special other than display “Welcome to my home page!”, but it will only do it if the current page is the home page. You can place this in your sidebar.php file and it will only appear when you click onto the home page. Like I said, this piece of code is nothing special but thing about just how helpful these conditionals can be when designing your site.
Here is a list of tags that I use the most.

  • is_home(): appears only on the home page
  • is_single(): appears only on that specific post
  • is_page() : appears only on that specific page
  • is_category() : appears only when in a specific category

These are only the few of the conditional tags offered by WordPress. Check out the WordPress codex for a complete list and more examples.

Share this:

Email
Facebook
Twitter
Pinterest
Pocket

Premium Themes for WordPress

Looking for an easy-to-use Premium Theme for WordPress? Check out Themes by bavotasan.com and have your site up and running in no time.

Use this WordPress website builder to build powerful websites in no time for your or your clients.

WordPress Hosting

WP Engine – designed from the ground-up to support and enhance the workflow of web designers.

Bluehost – providing quality web hosting solutions since 1996.

About the author

Picture of Luke Perrie

Luke Perrie