Once You Know, You Newegg

WP – “X” on home page only

Below code allows me to display something or execute something only on the home or front page of a site.

<?php if ( is_front_page() ) { ?>
Insert a “home page only” item.
<?php } else { ?>
Insert what appears on the rest on the pages/posts.
<?php } ?>

This can be easily added into a templates single.php, page.php, header.php, footer.php or where ever you need it.

A great use for this is banners.

For example: I want a small flash presentation to play once and not repeat as the site is navigated.

Using the above tag, I can create a quick solution.

<?php if ( is_front_page() ) { ?>
<img src=”an_image_or_flash_embed_for_only_home_page.png”>
<?php } else { ?>
<img src=”another_image_or_flash_embed_for_the_rest.png”>
<?php } ?>

Leave a Reply

Your email address will not be published. Required fields are marked *