None of the following are working to display conditional format in the sidebar when the current page is the home page:
- is_front_page,
- is_page(‘home’),
- is_page(id)
I added an else clause which is implemented on the home page.
In Options > Reading, I have specified a page called Home to be the front page. The slug ‘home’ and the page id of 13 (obtained from the URL when editing the Home page) all return false.
If I place <?php the_ID(); ?>
in the sidebar, it displays the post ids of blog posts which are also displayed (title only) by home.php (which is the template assigned to the home page).
I don’t know how else to explicitly display the page id on the front end so I know I’m using the correct id.
Try putting a wp_reset_query function call after your loop on the homepage template.
If you’re using a custom query on the home page and not used
wp_reset_query
, then the conditional check will always point to the last post fetched by that custom query hence failing to check if homepage.Without seeing exactly what’s going in your code, it sounds like the spot you are testing the page ID within the sidebar is already within a loop displaying posts on your sidebar.
Try running your conditional test before the sidebar loop begins, possibly storing it in a different variable in your home.php file and checking that variable in the sidebar instead of the current post ID