Skip to content

Instantly share code, notes, and snippets.

@ekka21
Created July 6, 2012 05:12
Show Gist options
  • Save ekka21/3058240 to your computer and use it in GitHub Desktop.
Save ekka21/3058240 to your computer and use it in GitHub Desktop.
Wordpress: set default thumbnail if NULL
add_action( 'save_post', 'wptuts_save_thumbnail' );
function wptuts_save_thumbnail( $post_id ) {
// Get Thumbnail
$post_thumbnail = get_post_meta( $post_id, $key = '_thumbnail_id', $single = true );
// Verify that post is not a revision
if ( !wp_is_post_revision( $post_id ) ) {
// Check if Thumbnail exists
if ( empty( $post_thumbnail ) ) {
// Add thumbnail to post
update_post_meta( $post_id, $meta_key = '_thumbnail_id', $meta_value = 'http://yoursite.com/your_image_url.jpg' );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment