WordPress Front Page vs Home Page and getting post ID outside or after the loop in every possible way

I was recently working on a site that needed to display the featured image of every page in its sidebar.

On regular, static pages or posts, everything works as intended – you can use is_page(), is_single() and get_the_ID() and not worry about anything.

// This works well on static pages or posts,
// displaying the featured image
if ( is_page() || is_single() ) {
    if ( has_post_thumbnail( get_the_ID() ) ) {
        the_post_thumbnail( 'full' );

However, on pages that contain the Loop (blog posts page, custom loop pages), things can get a bit complicated. I’ll walk you through a bunch of different solutions you can use to get the post/page ID, depending on the situation.

Continue reading