Sometimes you wish to show image, video or a piece of code, text or an advertisement only on your site’s homepage and 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.
Homepage-Only Sidebar, Header or Footer:
First options is to create a homepage-only 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:
Create new homepage specific file (sidebar-home.php, footer-home.php or header-home.php)
Add whatever you need to your file
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:
This method is a bit hard 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.
Checking If Is_Font_Page:
In my opinion this is the easiest 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:
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.