2

I'd like to add a Featured image to a default article or a Custom Type Post in my theme but I don't get the area of the highlight image, why? In the default theme the option is present but not in my theme, what have I missed?

2
  • Do you mean the Featured Image?
    – Jared
    Commented Jan 23, 2012 at 19:38
  • yes sorry, I have the Italian version!
    – vitto
    Commented Jan 23, 2012 at 19:39

1 Answer 1

4

You need to add theme support in the functions.php file of your active theme like this:

if ( function_exists( 'add_theme_support' ) ) { 
  add_theme_support( 'post-thumbnails' ); 
}

To enable it within a custom post type, you will need to do so when registering your post type with the supports argument, so you'll need to add something to your already existing code that registers your post type like so (this is an example):

$args = array(
  'labels' => $labels,
  'public' => true,
  'publicly_queryable' => true,
  'show_ui' => true, 
  'show_in_menu' => true, 
  'query_var' => true,
  'rewrite' => true,
  'capability_type' => 'post',
  'has_archive' => true, 
  'hierarchical' => false,
  'menu_position' => null,
  'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
); 
register_post_type('book',$args);

If you see the last line of the $args array, there's thumbnail in the supports array. That enables it for the custom post type.

See the Codex for more information:

For adding thumbnail support: http://codex.wordpress.org/Post_Thumbnails

For registering post types: http://codex.wordpress.org/Function_Reference/register_post_type

Or more specifically, a complete example with thumbnails added to a custom post type is here:

http://codex.wordpress.org/index.php?title=Function_Reference/register_post_type&oldid=112358#Example

3
  • 1
    And once you have added theme support, you must also add thumbnails to a custom post type when registering it, in the 'supports' parameter codex.wordpress.org/Function_Reference/… Commented Jan 23, 2012 at 19:49
  • Just updated my answer with this info. :)
    – Jared
    Commented Jan 23, 2012 at 19:50
  • good explanation! Commented Jan 23, 2012 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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