WordPress Hack: Using WordPress Conditional Tags
June 7, 2008 by Tony | Tag(s): Conditional Tags, WordPress Code, WordPress Hacks
Have you ever noticed how some pages on blogs behave different than on other pages? One of the most under-utilised features of WordPress is the wide variety of conditional tags available in WordPress. Through the use of conditional tags, you can instruct certain plugins, pictures, or code to only appear on designated pages.
Recently I ran across a post by the Undersigned explaining Conditional Tags in WordPress, which appears was written in 2006 but is still valid with current versions of WordPress.
Here is a list of the conditional tags available:
- is_home()
- is_single()
- is_page()
- is_category()
- is_author()
- is_date()
- is_year()
- is_month()
- is_day()
- is_time()
- is_archive()
- is_search()
- is_paged()
- is_404()
One of my favorite places to use conditional tags is in the post meta area. For example, on most pages I want the comments button to display, but I don’t need it to appear on the single page because the comments are displayed on that page. At the same time, I like having an edit button on the single page, but I don’t need it on any other pages.
Here is the code I use for the above example on one of my sites:
<?php if (is_single()){ ?> <?php edit_post_link(__(”*Edit*”), ”); ?> <?php } else { ?> | <?php comments_popup_link(’0 comments’, ‘1 comment’, ‘% comments’); ?> <?php } ?>
The bold code is the conditional tags I’ve set up. You can see from the above code that I am telling WordPress to only display an Edit button on single pages, and on all other pages display the comments link.
What other good uses have you found for conditional tags?
Related WordPress Posts
- How To: Make your WordPress Search Results Unlimited (0)
- How To: Adding an Email This Button to Your Blog (0)
- How To: Feature Posts From a Particular Category (0)
- How To: Adding a Print This Button to Your Theme (1)
- Improve Your Sites Behavior With WordPress Conditional Tags (0)
- Ultimate Guide to the WordPress Loop (0)

![Subscribe to [Blog Tutorials]](http://blogtut.com/wp-content/themes/BlogTutorialPro/images/rss.gif)
![[del.icio.us]](http://blogtut.com/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://blogtut.com/wp-content/plugins/bookmarkify/digg.png)
![[Facebook]](http://blogtut.com/wp-content/plugins/bookmarkify/facebook.png)
![[Google]](http://blogtut.com/wp-content/plugins/bookmarkify/google.png)
![[MySpace]](http://blogtut.com/wp-content/plugins/bookmarkify/myspace.png)
![[Newsvine]](http://blogtut.com/wp-content/plugins/bookmarkify/newsvine.png)
![[Reddit]](http://blogtut.com/wp-content/plugins/bookmarkify/reddit.png)
![[Slashdot]](http://blogtut.com/wp-content/plugins/bookmarkify/slashdot.png)
![[StumbleUpon]](http://blogtut.com/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Technorati]](http://blogtut.com/wp-content/plugins/bookmarkify/technorati.png)
![[Windows Live]](http://blogtut.com/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://blogtut.com/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://blogtut.com/wp-content/plugins/bookmarkify/email.png)






[...] certain functions only on pages of your choice. A couple of months ago we talked a little bit about WordPress conditional tags on this site and when to use them, but we didn’t get into a great amount of [...]