Skip to content

Instantly share code, notes, and snippets.

@ronalfy
Last active July 31, 2022 10:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ronalfy/4565131 to your computer and use it in GitHub Desktop.
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.
<?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