Make WordPress Core

Opened 4 years ago

Last modified 11 months ago

#18790 new defect (bug)

add_theme_support with post type doesn't add theme support but overwrites it

Reported by: Jesper800 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.2.1
Component: Themes Keywords: has-patch
Focuses: Cc:


The function add_theme_support has an optional second parameter, which allows you to add support for post thumbnails for certain post types.

You would expect this function to add the theme support for that post type, but instead it overwrites the theme support for that feature, which results in the theme support being set for just the post type(s) that were passed.


function add_thumbnails_support()
	add_theme_support('post-thumbnails', array('my_post_type'));
	add_theme_support('post-thumbnails', array('another_post_type'));

add_action('after_setup_theme', 'add_thumbnails_support');

Attachments (1)

18790.patch (790 bytes) - added by andrewsfreeman 3 years ago.

Download all attachments as: .zip

Change History (5)

#1 @kawauso
4 years ago

  • Keywords needs-patch added

#2 @toscho
4 years ago

  • Cc info@… added

#3 @andrewsfreeman
3 years ago

  • Cc andrewsfreeman added
  • Keywords has-patch added; needs-patch removed

I came across this problem today, wondering why my plugin didn't work as usual. A workaround I found was to just turn it on everywhere on init, but it would be nice to turn it on for a particular plugin's CPT.

My patch is simple - if it's already set and an array, merge the arrays. If it's already set to true (thumbnails everywhere), keep it true. Tested it on multiple CPTs and hooks.

It may possibly be redundant to make sure it is true, because otherwise it just wouldn't be set. Would be willing to re-upload if that is preferred.

Last edited 3 years ago by andrewsfreeman (previous) (diff)

#4 @obenland
11 months ago

I think I can get behind this. HTML% support works similarly. I wonder if this would cause any backwards compatibility concerns with implementations where developers counted on it being overwritten.

Note: See TracTickets for help on using tickets.