If Conditional tags for Wordpress themes

One year ago, I had some ”problems” with a wordpress theme because I wanted a simple thingy and I didn’t know how to do it: make certain stuff (ads, categories, widgets) to appear or disappear depending on the type of page I wanted to add them. This trick is good for placing, rotating ads especially in the header, sidebar and footer, based on conditional tags that are built in wordpress.

The first conditional tag that describes your index or home page is: is_home(). I will write you an example shortly but now I let me explain why you should use this. Let’s say you have an ad spot of 728×90px in your header or footer and in that spot you want a certain banner to appear when you are browsing the index page and another banner when you are reading a post or viewing a category page. For this you can place the following php cod in that spot:

if (is_home())
{
echo '<img src="bannerad.jpg"/>';
}

That was for the index, now for a single post the code looks like this and for a page you just change is_single() with is_page()

if (is_single())
{
echo '<img src="bannerad.jpg"/>';
}

So the wordpress conditional tags are very easy to use and handy, a bigger list of tags you can see and learn here at codex wordpress! This is just a simple introduction and I hope it helps you

Subscribe to my rss feed on Acosmin dot Com

If you like this blog please take a second from your precious time and subscribe to my rss feed

Related articles on Acosmin dot Com

3 Responses to “If Conditional tags for Wordpress themes”

Leave a reply

Name (*)

E-mail ( * )

URI

Message