Reputation: 55
Problem: On many Posts/Pages with no featured image shows () in the inspect element where the featured image/image attributes would be. Example page here: http://www.structural-innovations.com/2014/09/
Using PHP, how can I check if a page so that, then echo it out, and if not then do not echo this out.
Upvotes: 0
Views: 85
Reputation: 738
Use the conditional tags to check whether it is post or page: https://codex.wordpress.org/Conditional_Tags
And then use has_post_thumbnail function to verify that if this page has featured image or not.
Upvotes: 0
Reputation: 1477
This is what you want to look at.
https://codex.wordpress.org/Function_Reference/has_post_thumbnail
<?php
// Must be inside a loop.
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
else {
echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/thumbnail-default.jpg" />';
}
?>
Taken from the Wordpress Codex if the Post has a featured image display it if not then it will print a default thumbnail.
Upvotes: 2