Adding Featured Image to a new post – Idea
-
Featured image setting is not working for the new post. Maybe you know that the modal window displays the homepage instead of media library.
The solution might be as following: generate featured image from the first image in the post automatically. After that the author can change featured image normally. You may also add a notification after the text “Not updated until post is saved” saying “Please, add at least one image to the content”. After saving the post the featured image will appear. Here is the code I used in functions.php to generate featured image from the first in post.function auto_featured_image() { global $post; if (!has_post_thumbnail($post->ID) && get_post_type($post->ID) == 'post') { $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" ); if ($attached_image) { foreach ($attached_image as $attachment_id => $attachment) { set_post_thumbnail($post->ID, $attachment_id); } } } } // Use it temporary to generate all featured images /* add_action('the_post', 'auto_featured_image'); */ // Used for new posts add_action('save_post', 'auto_featured_image'); add_action('draft_to_publish', 'auto_featured_image'); add_action('new_to_publish', 'auto_featured_image'); add_action('pending_to_publish', 'auto_featured_image'); add_action('future_to_publish', 'auto_featured_image');
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Adding Featured Image to a new post – Idea’ is closed to new replies.