Larson
Larson

Reputation: 53

How to write if statement for "post don't have featured image"

How can I say to Wordpress to insert something if post does NOT have featured image. I can not use if-else. I need to use only if, so if "post don't have featured image" and then I'll add what to do.

I was thinking something like:

<?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail(' false '))  ) { ?>

but above is not working...

Above code will go into loop, in a specific page.

Please note I am total noob and not a coder neither, so please give me detailed explanation how to do something. Thanks a LOT.

Upvotes: 0

Views: 730

Answers (1)

trex005
trex005

Reputation: 5115

For a non coder, you were pretty hot on the trail. Assuming you are in THE LOOP you can use :

<php if(!has_post_thumbnail()){ 
     //Your stuff here
}?>

If you are NOT in THE LOOP, you just need to pass the post's ID

<php if(!has_post_thumbnail($post_id)){ 
     //Your stuff here
}?>

The ! symbol is for "not" which says if the post does not have a post thumbnail.

Upvotes: 1

Related Questions