Here’s 4 code snippets you can use to create a widget which only displays on the first page of your front page or home page (posts page).
You can use either your front page or a custom blog page as your posts page using the Reading Settings.
This PHP code simply registers a new widget which displays before your blog posts loop on the front page of your site.
The content of your widget will only display on the first page and not on paginated pages.
Note: All PHP code needs to be copied from the view raw link and pasted at the end of your child themes functions.php file.
You can use this code when use these Reading Settings:
Note: You can also use the is_home() conditional tag in replace of the is_front_page conditional tag when using the default Reading Settings to display posts on your front page.
Custom Blog Page – Not Front Page
If you have created a static page for your front page and using another page with the blog page template, use this code instead.
This code works when your Reading Settings look like this:
Note: If you use front page displays latest posts, this code will not display the widget before your loop on a custom blog page.
It will display the widget content on your front page.
Learn more about Using Conditional Tags For Home, Front & Blog Pages
Alternative Method
This method uses get_query_var which enables you to further customize where you want your widget to display.
Other Themes
This code should work with any theme as it uses a WordPress hook. Tested on both Twenty Eleven default theme for WordPress and Genesis 2.0 Sample child theme running HTML 5.
Clarification Of Using is_home() Conditional Tag
Note: Use of the is_home() conditional tag depends on your Reading Settings.
If your Reading Settings are set to: Front page displays > Your latest posts, then the is_home() conditional tag will return true for your front page.
If your Reading Settings are set to: Front page displays > A static page (select below) , then the is_home() conditional tag will return true for your blog page and not your Front Page.
Leave a Reply
You must be logged in to post a comment.