/ Published in: PHP
set post thumb if missing on post save
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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); } } }