Add Widget Before Loop On First Page of Front Page or Posts Page

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:

default 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:

reading settings

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.


Comments

4 responses to “Add Widget Before Loop On First Page of Front Page or Posts Page”

  1. This is by far the most educative site for Genesis framework users. I’m going to implement some of your tips & tricks and let me know if I can be of any help to you in exchange for the great tutorials on your website.

    1. Brad Dalton Avatar
      Brad Dalton

      No worries. Let me know if you get stuck.

  2. That’s why I love Genesis: it’s a modular framework that lets you add bits of code here to enable things and lets you un-register things you don’t need.
    Thanks Brad for all your tutorials, they are really good and I think one day day you could put everything into a book about customizing Genesis.

    1. Brad Dalton Avatar
      Brad Dalton

      hahaha. Feel like i’ve already written a few books already but its a good idea.

      Me too with Genesis. Just gets better and better.

      Working on some really good posts at the moment so more to come very soon.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.