In this post, i’ll teach you what the difference is between the 4 conditional tags for:
- Your Blog page
- Your Home Page
- Your Front Page
- Your Blog Page Template
The code you should use depends a lot on your Reading Settings.
Blog Page
If you want to display content only on your blog page, the same conditional tag you use may not work in all circumstances.
It depends on your Reading settings. If you’re set your Reading settings to display a static page on the front page and selected your blog page as the page display post on, then using the is_home() conditional tag in a custom function in your child theme, will display your content on your blog page.
Example Code:
add_action('genesis_before_loop', 'content_before_blog_page');
function content_before_blog_page() {
if(is_home() ) {
echo "Hello World";
}}
This code will not work if you have not selected the exact same settings in the above screenshot.
It doesn’t matter how many pages you have used with the blog page template. Only the one selected in the reading settings for your Posts Page will display the content you use in a custom function with the is_home()
conditional tag.
Your static front page will not display the content when using the is_home()
conditional tag.
Another method is to use the genesis_is_blog_template()
conditional tag to target any page using the Genesis blog page template.
Home Page
Here’s the Reading Settings which work with the is_home() conditional tag.
If you’re using your front page to display your posts which many themes do by default like shown in the screenshot above, then you can use the is_home()
conditional tag in a custom function like this:
add_action('genesis_before_loop', 'content_before_blog_page');
function content_before_blog_page() {
if(is_home() ) {
echo "Hello World";
}}
The above code will display your content on the front page as long as you haven’t changed the default Reading Settings.
It doesn’t matter if you have setup a custom blog page as well and used the blog page template your themes provides an an option under your Page Attributes. In this case the is_home()
conditional tag will not display your content on your blog page.
You can also use the is_front_page()
conditional tag in this case or even use them together.
add_action('genesis_before_loop', 'content_before_blog_page');
function content_before_blog_page() {
if(is_home() AND is_front_page() ) {
echo "Hello World";
}}
Or like this:
add_action('genesis_before_loop', 'content_before_blog_page');
function content_before_blog_page() {
if(is_home() || is_front_page() ) {
echo "Hello World";
}}
Front Page
If you have selected to use a static page as your front page, you can use the conditional tag is_front_page
to display content on your front page.
Here’s the code you can use in your child themes functions.php file.
add_action('genesis_before_loop', 'content_before_blog_page');
function content_before_blog_page() {
if(is_front_page() ) {
echo "Hello World";
}}
You can also use this conditional tag even if you have selected to display your latest posts which is the default setting.
Blog Page Template
Genesis users can also use the is_page_template()
conditional tag to display content only on pages using this template.
If you want to use this conditional tag to display content on your blog page, you will also need to use the correct Reading Settings.
Firstly, here’s a working example of how to use the is_page_template()
to display content on your blog page.
add_action('genesis_before_loop', 'content_before_blog_page');
function content_before_blog_page() {
if ( genesis_is_blog_template() )
echo "Hello World";
}
Using page_blog-php or blog-php will not work so you need to be extra careful to make sure you get it right.
Using the code snippet above only works when you use the correct Reading Settings.
The Reading Settings selected in the below screenshot won’t display your content on the page you have selected as your Posts Page when using this code above.
The code will work to display content on any other page using the blog page template which probably isn’t want you want.
If you use another page as your posts page and also have created a different page for your blog like in this screenshot below, then the code will work to display your content on all other pages using the blog page template and exclude the page you selected as your Posts Page.
The default settings which you see in the screenshot below will make the code display your content on any pages using the blog page template but that’s also probably not what you want because the default settings also make your latest posts display on the home page so you won’t need a custom blog page.
So What Works?
As shown earlier, the is_home()
conditional works for displaying content on your blog page when you have selected a static page as your front page and your blog page as your posts page in your Reading Settings.
add_action('genesis_before_loop', 'content_before_blog_page');
function content_before_blog_page() {
if (is_home() ) {
echo "Hello World";
}}
You don’t even need to select the blog page template or even name your page blog or even use a permalink with the name blog. It works based on what you select in the Reading Settings.
Learn More About Adding a Widget Before Loop On First Page Of Posts Page
Was This Tutorial Helpful?