You are here: Home/Blog/Code/ Add A Conditional Widget To Genesis Blog Home Page

Add A Conditional Widget To Genesis Blog Home Page

Last updated

Problem: We want a widget area that displays only on the home page blog, and we only want it to display in the first page of the archive.

Here’s how our widget are will look and behave once we’re done.

Here’s how we’re going to implement this

Add the following to your child themes functions.php file

This code registers a widget area and defines the markup.

In your Reading Section make sure that your front page is set to show your latest,

Create a file called front-page.php in your child theme and add this

Note: If this file already exists, simply append it before genesis(); is called.

This code will check if our is_home() is true which means we’re on the blog page, and if we have any posts. If those conditions are met then we check if which page where are on in the archive. If it’s page 1 of the archive then we are going to display our widget.

There’s probably a better way to do this without having to touch the front-page.php, but after messing with it for a while I was having trouble with testing for the right conditionals in functions.php alone.

Style Your Widget And Add Content

Here are some default styles I created, but you can go crazy here. This goes in your child themes style.css file.

Note: Sometimes I post affiliate links for awesome products that I use and love and will earn a commission if you purchase through my link. If you think the information I provide is useful please use my link to make a purchase thank you.