Return to Snippet

Revision: 56987
at April 28, 2012 04:51 by lolitaloco


Initial Code
function init_set_thumb() {
	add_action('save_post', 'set_post_thumb', 10);
}	
add_action('admin_init', 'init_set_thumb');

function set_post_thumb($post_id) {
	if(!wp_is_post_revision($post_id)) {
		$post_type = get_post_type($post_id);
		$post_thumb = get_post_thumbnail_id($post_id);
		if($post_type == 'post' && !$post_thumb) { // if post type = post and get_post_thumbnail == false
		 	$defaultimage = 1; // set to id of attachment to use as default post thumb			
			set_post_thumbnail($post_id,$defaultimage); 
		}			
	}
}

Initial URL

                                

Initial Description
set post thumb if missing on post save

Initial Title
Set post thumb to default if missing on post save

Initial Tags
wordpress

Initial Language
PHP