Skip to content

Instantly share code, notes, and snippets.

@cobbman
Last active December 15, 2015 21:09
Show Gist options
  • Save cobbman/5323173 to your computer and use it in GitHub Desktop.
Save cobbman/5323173 to your computer and use it in GitHub Desktop.
WordPress: Add a featured image to the blog page (more difficult than regular)
<?php
/****** featured image for blog page ******/
$page_for_posts = get_option('page_for_posts'); // gets the ID of the page that displays posts
$default_attr = array( // these are the attributes that can be passed to the image. See WP codex for all options.
'class' => "featured-header-image",
);
global $wp_query;
if ( $wp_query->is_posts_page && // check that we are on the posts page, and have a featured image first. Redundant.
has_post_thumbnail( $page_for_posts ) &&
( $image = wp_get_attachment_image_src( get_post_thumbnail_id( $page_for_posts ), 'full' ) ) ) :
echo "<div class='banner-image'>"; // wrap the image in html if you want to!
echo get_the_post_thumbnail( $page_for_posts, 'full', $default_attr );
echo "</div>";
endif;
/****** end featured image for blog page ******/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment