I have this code inserted in the Function.PHP file of my wordpress this. What it basically do is:
when ever the user clicks the pinterest button, it ignores all the images in the blog post page but instead choose/return the feature image to be pinned.
function catch_that_image( $size = 'full' ) {
global $post;
if ( has_post_thumbnail($post->ID) ) {
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), $size);
return $featured_image[0];
}
return false;
}
I have no problem with the code above, but then I realized that what if there’s no featured image?
Is it possible if someone can modify the code for to to add the following IF and Else Condition:
IF Featured Image is Present:
Run the script above. (I think it’s covered in the above code and works fine)
BUT IF THERE’S NOT FEATURED IMAGE, choose/return a default image to be pinned.
I’m not really sure how to integrate this code (below) to above code. Sorry but i lack of knowledge in this area.
if(empty($first_img)){ //Defines a default image
$first_img = "http://www.mywebsite/wp-content/themes/Default_Image.jpg";
}
THank you verymuch
Use the following code: