Categories: Snippets

has_post_thumbnail() not working

Assuming that you’re in The Loop, you can fix this problem, by replacing:

if ( has_post_thumbnail() ) {
     // do a bunch of stuff
}

with

$featured_image_url = wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) );
if  ( ! empty( $featured_image_url ) ) {
     // do a bunch of stuff
}

 

Recent Posts

Adding or Including custom post type to default WordPress loop

Adding or Including custom post type to default WordPress loop by altering the 'pre_get_posts' function.…

5 years ago

How to Limit or Disable WordPress Post Revisions

Limit the number of posts revisions that WordPress stores in the database. edit wp-config.php file…

5 years ago

Multisite – List Recent Posts Across an Entire Network

In Multisite, List Recent Posts Across an Entire Network by using custom query or WP_Query…

5 years ago

Disable update notification for individual plugins / All

code for the plugin file itself:- [crayon-662f8e3d6b661446304283/] I like to put this in the actual…

5 years ago

How to change the WordPress permalink structure to remove dates from the URLs

Switching the permalink structure from /year/month/post-slug to just /post-slug is easy by going to Settings…

6 years ago

Limit character in content and title in wordpress

[crayon-662f8e3d6b925598540771/] or with readmore [crayon-662f8e3d6b92a264175651/]  

6 years ago