Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function autogen_featured_img() {
- global $post;
- if (!has_post_thumbnail($post->ID)) {
- $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);
- }
- }
- }
- }
- /*This line is used to generate featured images for all old
- posts. Remove this once the default images get generated
- for all of the old posts*/
- add_action('the_post', 'autogen_featured_img');
- /* For new upcoming posts, leave them permanently*/
- add_action('save_post', 'autogen_featured_img');
- add_action('draft_to_publish', 'autogen_featured_img');
- add_action('new_to_publish', 'autogen_featured_img');
- add_action('pending_to_publish', 'autogen_featured_img');
- add_action('future_to_publish', 'autogen_featured_img');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement