WordPress Conditional Title Loop

While working on a WordPress site for a client, I needed to load a header logo based on a term that was present in the title tag of page. While there is lot of stuff out there about using the conditional loops for pages, categories, etc. you really have to dig to find something like what I need.

So, in case somebody stumbles across this looking for the same thing, this might save you some time.

In the header.php file of the theme you are working with, you need to place the following in the area that you need to setup the condition. For my use, I had it serve up an image.


elseif (stripos($post->post_title, ‘TITLETERM’)!==false) {

print(‘<img alt=”” src=”/wp-content/themes/themes/images/main-top.jpg” height=”101″ width=”800″ align=”left”/>’);

} else

print(‘<img alt=”” src=”/wp-content/themes/themes/images/main-top2.jpg” height=”101″ width=”800″ align=”left”/>’);  [/code]

And that’s it. Not too difficult at all to do.

You could expand this to add other terms as needed.