is_home() and is_front_page() not working in sidebar

I'm trying to display a custom widget in the sidebar of my homepage (which is a static front page defined in Settings Reading). Here is the relevant part of my sidebar.php:

if ( is_front_page() || is_home() ) {
    if ( is_active_sidebar( 'sidebar_lecture' ) ) : ?
        div id="secondary" class="widget-area" role="complementary"
            ?php dynamic_sidebar( 'sidebar_lecture' ); ?
        /div
    ?php 
endif;

The sidebar does not display because the conditional tag does not recognize my homepage as being a homepage.

When I print_r($wp_query) in the sidebar, it reveals that [is_page] = 1 and that the post's [ID] = 32, which is correct. However, [is_home] is null.

For the record, I did use a custom query (query_posts()) in my page.php template, but I did reset it afterwards using wp_reset_query().

Any pointers?

Topic conditional-tags sidebar homepage Wordpress

Category Web


You can missing the semicolon at the end of the code. please replace the code with my code.

       if ( is_front_page() || is_home() ) {
           if ( is_active_sidebar( 'sidebar_lecture' ) ) : ?>
                <div id="secondary" class="widget-area" role="complementary">
                    <?php dynamic_sidebar( 'sidebar_lecture' ); ?>
                </div>
              <?php 
            endif;
        }

I hope it's work.


I was having the same issue but found an anwser that worked for me. When you use wp_reset_query(); before you use is_home(); or is_front_page(); it will work just fine.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.