Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. function autogen_featured_img() {
  2. global $post;
  3. if (!has_post_thumbnail($post->ID)) {
  4. $attached_image =
  5. get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
  6.  
  7. if ($attached_image) {
  8. foreach ($attached_image as $attachment_id => $attachment) {
  9. set_post_thumbnail($post->ID, $attachment_id);
  10. }
  11. }
  12. }
  13. }
  14. /*This line is used to generate featured images for all old
  15. posts. Remove this once the default images get generated
  16. for all of the old posts*/
  17. add_action('the_post', 'autogen_featured_img');
  18. /* For new upcoming posts, leave them permanently*/
  19. add_action('save_post', 'autogen_featured_img');
  20. add_action('draft_to_publish', 'autogen_featured_img');
  21. add_action('new_to_publish', 'autogen_featured_img');
  22. add_action('pending_to_publish', 'autogen_featured_img');
  23. add_action('future_to_publish', 'autogen_featured_img');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement