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?













There Are 5 Responses So Far »
Pingback: WordPress Conditional Tags - Posted In WordPress | Bayu Albelly - .SlackbloG Journal
Pingback: Compilation of WordPress Hacks
Pingback: 100+ Killer Wordpress Resources | Steffan Antonas’ Blog
Pingback: links for 2008-09-29 » Anidan Design
Pingback: Collection of WordPress Hacks | WordPress Hacks
Pingback: WordPress Resources - 48 Resources, Tips, Tricks & Themes | Think Design