0

In the past when I created a news post, the featured image was automatically assigned to the post when I uploaded an image in the post.

But now, that doesn't work anymore :( The only thing that changed was that I installed certain plugins for testing and deactivated them afterwards.

First I found out that I didn't add theme support for featured images. Added this code in my functions.php:

// This theme uses post thumbnails
add_theme_support( 'post-thumbnails' ); 

I can now see the featured images in the back-end and add it manually. But how come it was automatically in the past?

I'm using WordPress 3.7.1–nl_NL with my custom theme and the following plugins:

  • All In One SEO Pack
  • Google XML Sitemaps
  • Jetpack by WordPress.com
  • Limit Login Attempts
  • SI CAPTCHA Anti-Spam
  • WP Anti Spam
  • WordPress does not automatically assign featured images. What Theme were/are you using, and what Plugins are active? I assume you have changed the Theme. If so, you will need to identify the previous Theme, and the code that Theme used to auto-assign featured images. – Chip Bennett Nov 19 '13 at 13:38
  • @ChipBennett, I did not change theme, I'm still using my own custom theme. I've added the active plugins to my question. – gelleby Nov 19 '13 at 13:44
0

You need to create a function for that. Use this code below in your functions.php file and it will add a featured image automatically:

/* Generate Featured Image Automatically */

function autoset_featured() {
          global $post;
          $already_has_thumb = has_post_thumbnail($post->ID);
              if (!$already_has_thumb)  {
              $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);
                                }
                           }
                        }
      }
add_action('the_post', 'autoset_featured');
add_action('save_post', 'autoset_featured');
add_action('draft_to_publish', 'autoset_featured');
add_action('new_to_publish', 'autoset_featured');
add_action('pending_to_publish', 'autoset_featured');
add_action('future_to_publish', 'autoset_featured');
0

...how come it was automatically in the past?

—it has no answer actually. Any intertwining code can filter featured image from your post, or you could misunderstand the thing at past - anything can be - I have no idea.

The thing is that: to show the post thumbnail into anywhere, whether in home page (blog feed) or in post detail page, you need to call another function:

the_post_thumbnail();

To show featured image on home page, use the code in index.php (or any interlinked template), and to show into the detail page, use the code in single.php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.