Sometimes, you may want to display some content only on specific pages or sections. For example, you may wish to display a welcome message on your blog homepage or show specific information on the Categories page. In this recipe, Let's learn how to do it with the help of WordPress conditional tags.
WordPress conditional tags are Boolean variables so you have to use them as a condition on a
php
if
statement as shown in the following example:<?php if(is_page()) { echo "Page title:"; the_title; } ?>
The preceding
if
statement will returnfalse
if the current page template isn't a WordPress page template so nothing would happen. Otherwise, theif
statement will returntrue
and will print the page title on screen.Conditional tags can be used in any theme files.
WordPress features a large amount of conditional tags for all needs...