Setting post image automatically as featured image for post thumbnail
Before using this code I use different types of plugins for showing post thumbnail. But this below code helps me to set my post image automatically as my thumbnail/ featured image, not only that , this code also set a default thumbnail
paste this code into functions.php file
// Get URL of first image in a post
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('//i', $post->post_content, $matches);
$first_img = $matches [1] [0];
// no image found display default image instead
if(empty($first_img)){
$first_img = "http://newsprotidin.com/wp-content/uploads/2013/02/thumb-150x150.jpg";
}
$first_img = vt_resize( $first_img, '', 460, 250, true );
return $first_img;
}
paste this code into functions.php file
// Get URL of first image in a post
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/
$first_img = $matches [1] [0];
// no image found display default image instead
if(empty($first_img)){
$first_img = "http://newsprotidin.com/wp-content/uploads/2013/02/thumb-150x150.jpg";
}
$first_img = vt_resize( $first_img, '', 460, 250, true );
return $first_img;
}