WordPress Tricks: Add a div or other element to one specific page or page type

 

Here is the code I use to add a div or image or other element to just one page or category page of my WordPress sites:

This code will add a div with the id “featured_content” only on the home page:

<?php if ( is_home() ) { ?>
<div id="featured_content">
&nbsp;
</div>
<?php } ?>

 

This code would add a div with the id “featured_recipe” to all posts in the category “recipes.”:

<?php if ( is_category('recipes') ) { ?>
<div id="featured_recipe">
&nbsp;
</div>
<?php } ?>

 

This code would exclude “myimage.jpg” only on the Contact page:

<?php if ( !is_page('contact') ) { ?>
<img src="myimage.jpg">
<?php } ?>

 

As you can see, there are many uses and ways implementations of this code. Let me know if you have any questions or need further assistance.

Meet the author

Libby Fisher is an experienced freelance web developer, recently relocated from Seattle to Boston, and passionate about developing websites that are both aesthetically appealing and intuitively usable - or as she prefers: "beautifully effective."