Tag Archives: tags

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.

True or False: HTML Tags are case sensitive

[wpsqt_quiz name="True or False: HTML Tags are case sensitive"]

 

Note: the source for this quiz is http://www.computerhope.com/answer.htm

WordPress: How to show a div on only certain pages

Here is the code you can use to show a <div> on only the pages that you want it to be shown on:

<?php if( is_page(home) ) { ?> 
<div> This is the div that will only show up on the page named 'Home' </div> 
<?php } ?>

You can also have it show up on every page except for a particular page:

<?php if( !is_page(home) ) { ?>
<div> This is the div that will only show up any page that is NOT named 'Home' </div> 
<?php } ?>

Let me know if you have any questions or trouble with this at all.