Skip to content

Instantly share code, notes, and snippets.

@johnpbloch
Created October 25, 2012 16:49
Show Gist options
  • Save johnpbloch/3953977 to your computer and use it in GitHub Desktop.
Save johnpbloch/3953977 to your computer and use it in GitHub Desktop.
Automatically add featured image
<?php
function _jpb_featured_image_setup(){
define( 'JPB_THEME_REALLY_SUPPORTS_POST_THUMBNAILS', current_theme_supports('post-thumbnails') );
if(!JPB_THEME_REALLY_SUPPORTS_POST_THUMBNAILS){
add_theme_support( 'post-thumbnails' );
}
}
add_action('after_setup_theme', '_jpb_featured_image_setup', 101);
function _jpb_featured_image_insert($content){
if(JPB_THEME_REALLY_SUPPORTS_POST_THUMBNAILS || !has_post_thumbnail()){
return $content;
}
// grab the post_thumbnail and add any html you need to it
$image_html = get_the_post_thumbnail();
$image_html = "<div class='feature'>$image_html</div>";
return $image_html . $content;
}
add_filter( 'the_content', '_jpb_featured_image_insert' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment