Skip to main content
WordPress made easy with the drag & drop Total WordPress Theme!Learn More

Show Something Only On The WordPress Homepage

Last updated on:

Sometimes you have a piece of code, text or an advertisement you wish to show on your site’s homepage (and is not part of home.php) but you do not want to show it on all the other pages of your site. Below are two different ways you can do this. Both are really easy and even the biggest WP noob should be able to do it.

Checking If Is_Front_Page

In my opinion this is the best method to use. Basically you run a very quick php test to see if it’s the current page is front page of your site and if so show whatever. See the example code below:

<?php if ( is_front_page() ) { ?>
	Do stuff here
<?php } ?>

Checking If Is_Home

Alternatively you can check to see if the current page is the “homepage” and if so do something. See the example below:

<?php if ( is_home() ) { ?>
	Do stuff here
<?php } ?>

If Is_Home VS. Is_Front_Page

You are probably wondering what the difference between if “front_page” and “home“. It’s really simple. Basically the “front page” is the very first page of your site (the homepage) while “home” is the page where your latest posts is shown.

Use is_front_page whenever you want something to appear on the homepage no matter if it’s a static page or your latest posts.

Use is_home when you want to show something on the main blog page even if it’s not set as the homepage.

The Alternative Homepage-Only Sidebar, Header or Footer

Another options is to create a homepage-specific sidebar, header or footer that contains the code, text or advertisement that you wish to show only on the homepage. To do this just follow the simple steps below:

  1. Create new homepage specific file (sidebar-home.php, footer-home.php or header-home.php)
  2. Add whatever you need to your file
  3. Call new file on the home.php or index.php file (whichever your template is using for the homepage) – to do so simply use one of the methods below:
<?php get_header( home ); ?>

<?php get_sidebar( home ); ?>

<?php get_footer( home ); ?>

This method is a bit more of a pain in the a** because you have to create new files. However, it works well and if you have a completely different sidebar, footer, header for the homepage it may be a good way to keep things organized in your theme’s files.

Questions? Comments?

If you have any questions or comments regarding the methods for conditionally showing content only on your WordPress homepage let us know in the comments so we can help you out. I’m sure many other people have the same questions and you’ll be doing everyone a service!

Subscribe to the Newsletter

Get our latest news, tutorials, guides, tips & deals delivered to your inbox.

5 Comments

  1. 042coded

    Hello, thanks for sharing i used those code. want i wanted is to display only on homepage not on pages like /1/, /2/ and the rest pls help

    • AJ Clarke

      To prevent the code from showing on the paginated pages you’ll want to also use the is_paged function. Example:

      <?php is_front_page() && ! is_paged() ) { ?> DO STUFF HERE <?php } ?>

  2. Bathri Vijay

    How to disable certain elements on Homepage? Please reply to my question.

    • Kyla

      The easiest way would be to create a custom homepage – either by coding a homepage template yourself, using a custom CSS plugin (like CSSHero) to remove elements or enabling a page builder (like Elementor) to design a homepage.

  3. Mike

    Thank you AJ for this guide you saved me from having to add another plugin on a client site or mess with custom fields for a homepage only tracking script I needed to add. I used is_front_page() before the closing tag in the header-single.php in the theme and confirmed it was homepage only and not showing on any posts or other pages. Cheers!!!!

Leave a Reply

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

Learn how your comment data is processed by viewing our privacy policy here.