Wordpress is_home () || is_index () maybe?

I have a test in my header.php to see if we have at home to show the hero or not.

<?php if ( is_home() && have_posts() ) : ?> <div id="hero" class="inner clearfix"> ... </div> <?php endif ?> 

But when the user lands on index.php, the hero is not displayed. apparently there is no is_index () condition, does anyone know how I can check if it has its home or index?

+6
source share
3 answers

Try is_front_page()

 <?php if ( is_home() || is_front_page() ) : ?> <div id="hero" class="inner clearfix"> ... </div> <?php endif ?> 

This should return true if you are on the absolute root of the site.

+17
source

Try:

 <?php if ( ( is_home() || is_front_page() ) && have_posts() ) : ?> <div id="hero" class="inner clearfix"> ... </div> <?php endif ?> 

If it still does not work, try adding the following immediately before the if :

 <?php wp_reset_query(); ?> 
+3
source

Try is_front_page() from the Wordpress Conditional Tag List .

This is true when you are on the "Front Page" of your wordpress installation, which:

  • The posts page if you have set your first page to your blog / posts
  • The page you specified as your main page if you use the page instead of your posts.
+2
source

Source: https://habr.com/ru/post/892793/


All Articles