WordPress- Only Display Element On Homepage

Image frame
WordPress- Only Display Element On Homepage
Maruf
Oct 20th, 2008
Maruf scribbled this post.

A lot of the files in WordPress are used as includes e.g Sidebar, header and footer. What if you want certain elements in those includes to appear just on the Homepage? I find myself needing that feature all the time.

Example

All you really need is one simple function. So for example, in your header you may have an image which you want to appear on the homepage:

BrightCherry Logo

The Code

1
2
3
4
5
6
7
<?
if (is_home()) {
?>
<img src="http://www.brightcherry.co.uk/images/logo.png" title="brightCherry Logo" alt="BrightCherry Logo" />
<?
}
?>

Now the image will only appear on the homepage!

Next time i’ll show you how to link specific elements to particular posts :)


Filed away: Wordpress

comments

Image frame
1

Thank you so much for this, you just made my day.

Aaron
Mar 2nd, 2009
Image frame
2

This made my day as well. I had a whole load of javascript in the header that was necessary for the homepage but not for any other and was throwing up “object required” errors in IE. I kind of “commented it out” with this trick which I couldn’t find in the codex. Thank you!!!

Rob Cubbon
Mar 12th, 2009

feel free to leave a scribble

Name:
Email:
gravatar
Want an image next to your comments?
visit gravatar.com
Message:
Get a free quote