0

is there a way / function to determine if Get the image plugin successfully grab the image from post? Something like has_post_thumbnail on WordPress featured image. I need to know if featured image exist, since other HTML elements (position absolute) / depend on the Featured image for positioning.

Thanks.

1
  • Currently the question is "have plugin. need feature.". Please instead show us what you've tried. See How to Ask for more info on how to improve your question-.
    – kaiser
    Oct 27, 2013 at 10:41

1 Answer 1

0

You can just run a conditional check on the result of get_the_image(). Either it will have returned an image or not.

if ( function_exists( 'get_the_image' ) ) {
  $image = get_the_image(array('echo'=>false));
  if( ! empty ( $image ) ) {
     // do something with the image

  } else {
     // do something if there is no image

  }

}
2
  • Hello, it's working. But, when I use $image variable, the image also got printed on post with image. Is there a way to get boolean value out of it like has_post_thumbnail? I'll use this way for the time being. Thanks.
    – Fujianto
    Oct 27, 2013 at 11:37
  • You can look at the get the image plugin code to see that echo is a function parameter and is true by default, but can be set to false. I've edited my code to show this change. If you're not really comfortable looking at get the image's code, then I'd suggested sticking with the built-in WordPress functions. Oct 27, 2013 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.