Last active
July 31, 2022 10:11
-
-
Save ronalfy/4565131 to your computer and use it in GitHub Desktop.
Use Auto-Generate-Thumbnail plugin to generate thumbnail images when has_post_thumbnail is erroring out. This assumes you are inside of the WordPress loop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Assumes within the WordPress Loop | |
$args = array ('title' => $post->post_title); | |
if ( strlen( $img = get_the_post_thumbnail( get_the_ID() ) ) ) { | |
/* display thumbnail */ | |
the_post_thumbnail( 'thumbnail', $args ); | |
} else { | |
delete_post_meta( $post->ID, '_thumbnail_id' ); | |
//Requires Auto Post Thumbnails plugin - http://wordpress.org/extend/plugins/auto-post-thumbnail/ | |
if ( function_exists( 'apt_publish_post' ) ) { | |
apt_publish_post( $post->ID ); | |
} | |
the_post_thumbnail( 'thumbnail', $args ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment