Opened 20 months ago
Last modified 9 months ago
#18790 new defect (bug)
add_theme_support with post type doesn't add theme support but overwrites it
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Themes | Version: | 3.2.1 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | info@…, andrewsfreeman |
Description
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.
Reproduce:
function add_thumbnails_support()
{
add_theme_support('post-thumbnails', array('my_post_type'));
print_r(get_theme_support('post-thumbnails'));
add_theme_support('post-thumbnails', array('another_post_type'));
print_r(get_theme_support('post-thumbnails'));
}
add_action('after_setup_theme', 'add_thumbnails_support');
Attachments (1)
Change History (4)
andrewsfreeman — 9 months ago
comment:3
andrewsfreeman — 9 months ago
- Cc andrewsfreeman added
- Keywords has-patch added; needs-patch removed
Note: See
TracTickets for help on using
tickets.

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.