Set Featured Image WordPress Not Working [RESOLVED!]

Jump to Solution »

Ok, so you’re going about your day like every other day. You found a helpful website and you’re eager to post about it. You log into your WordPress site and you see a new version of WP available, version 3.5. You think, “Ok cool, there’s a newer and better version of WordPress. I’m going to upgrade.” After upgrading you’re ready to add your post! After spending 20 minutes writing, you click “set featured image” to add your awesome thumbnail.

The popup window opens just like it always did, you choose “upload files” and found your files.

wordpress featured image popup

Waiting…waiting…waiting for the image to upload but you get an error message that looks like this:

wordpress featured image error

NOOOO! WordPress 3.5 how could you do this to me. You search frantically for an answer but even though you’ve:
1) Disabled ALL of your plugins
2) Switched to the Twenty (Ten, Eleven, or Twelve)…
the Set Featured Image still doesn’t work!

But what is even crazier is the fact that the image does in fact upload to your media library; it just doesn’t get set as your featured image. And this is what we’ll be attempting to fix today.

The simple answer would be to downgrade to wordpress 3.4.2.

Now, I’m still not quite sure what the problem is exactly (since no one can give a definite answer) but here’s a great workaround:

WordPress Custom Fields

In order to temporarily fix this problem, we’ll be using WordPress custom fields. Using custom fields will allow us to create input fields within our “edit post/page” pages and use those fields to add arbitrary info related to our post/page. First, you will need to open your index.php (or loop.php) depending on your theme.

Locate this portion of code (simplified for this example):

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
     <div id="post-<?php the_ID(); ?>" class="post">
          <?php if(has_post_thumbnail()) : the_post_thumbnail(); ?>
               <?php the_excerpt(); ?>
     </div><!-- end post -->
<?php endwhile; endif; ?>

Now what we’re going to do is this…Right below this code:

<?php if(has_post_thumbnail()) : the_post_thumbnail(); ?>

…we’re going to add a conditional statement that looks like this:

<?php
$key = get_post_meta($post->ID, $key, true);
if (!$key) : ?>
<img src="file/path/to/default/image.jpg" />
<?php else : ?>
<img src="<?php echo $key; ?>" />
?>

So this is what your code should look like now:

<?php
if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
     <div id="post-<?php the_ID(); ?>" class="post">
          <?php if(has_post_thumbnail()) : the_post_thumbnail(); ?>
          <?php
               $key = get_post_meta($post->ID, $key, true);
               if (!$key) : ?>
                    <img src="file/path/to/default/image.jpg" />
               <?php else : ?>
                    <img src="<?php echo $key; ?>" />
               <?php endif; 
          ?>
          <?php the_excerpt(); ?>
     </div><!-- end post -->
<?php endwhile; endif; ?>

The ‘key’ should be changed to something more specific such as: cf_post_thumbnail OR my_post_thumbnail. This will help you remember which “name” field to use when wanting to assign a URL to that field. Kinda confusing? Ok, screenshot:

custom field wordpress

Make sure that if you change ‘key’ to something else, that you reference that ‘key’ in your post Custom Field.

I hope that clears up a few things and helps a few of you out. Let me know how I could improve this post for others. Thanks!