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?
is_home
being null on a static front page is correct,is_front_page
is the one you should be looking at. also,query_posts
should never be used, useWP_Query
instead and polluting the global query object will be a non-issue.is_front_page()
is matching correctly. I was confused because when Iprint_r($wp_query)
,is_front_page
does not even show up as a property, while all the rest of the conditional tags are there. If it's not in the WP_Query object, then where is the "is_front_page" flag set?