Created
October 25, 2012 16:49
-
-
Save johnpbloch/3953977 to your computer and use it in GitHub Desktop.
Automatically add featured image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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