Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/add theme support

This page redirects to an external site: https://developer.wordpress.org/reference/functions/add_theme_support/

Description

Allows a theme or plugin to register support of a certain theme feature. If called from a theme, it should be done in the theme's functions.php file to work. It can also be called from a plugin if attached to an action hook.

If attached to an action hook, it should be after_setup_theme. The init action hook may be too late for some features.

Usage

<?php add_theme_support$feature$arguments ); ?>

Support should be added on the 'after_setup_theme' or 'init' action, but no later than that. It does not accept any further arguments.

function custom_theme_setup() {
	add_theme_support( $feature, $arguments );
}
add_action( 'after_setup_theme', 'custom_theme_setup' );

Parameters

$feature
(string) (required) Name for the feature being added.
Features list:
Default: None
$args
(array) (optional) Optional arguments (see below). If not passed it defaults to true.
Default: true

Addable Features

Post Formats

This feature enables Post Formats support for a Theme. This feature became available with Version 3.1. When using Child Themes, be aware that add_theme_support( 'post-formats' ) will override the formats as defined by the parent theme, not add to it.

To enable the specific formats (see supported formats at Post Formats), use:

add_theme_support( 'post-formats', array( 'aside', 'gallery' ) );

To check if there is a 'quote' post format assigned to the post, use

// in your theme single.php, page.php or custom post type
if ( has_post_format( 'quote' ) ) {
	echo 'This is a quote.';
}

Post Thumbnails

This feature enables Post Thumbnails support for a Theme. The feature became available with Version 2.9. Note that you can optionally pass a second argument with an array of the Post Types for which you want to enable this feature.

add_theme_support( 'post-thumbnails' );
add_theme_support( 'post-thumbnails', array( 'post' ) );          // Posts only
add_theme_support( 'post-thumbnails', array( 'page' ) );          // Pages only
add_theme_support( 'post-thumbnails', array( 'post', 'movie' ) ); // Posts and Movies

This feature must be called before the init hook is fired. That means it needs to be placed directly into functions.php or within a function attached to the 'after_setup_theme' hook. For custom post types, you can also add post thumbnails using the register_post_type function as well.

To display thumbnails in themes index.php or single.php or custom templates, use:

the_post_thumbnail();

To check if there is a post thumbnail assigned to the post before displaying it, use:

if ( has_post_thumbnail() ) {
	the_post_thumbnail();
}

Custom Background

This feature enables Custom_Backgrounds support for a theme as of Version 3.4.

add_theme_support( 'custom-background' );

Note that you can add default arguments using:

$defaults = array(
	'default-color'          => '',
	'default-image'          => '',
	'wp-head-callback'       => '_custom_background_cb',
	'admin-head-callback'    => '',
	'admin-preview-callback' => ''
);
add_theme_support( 'custom-background', $defaults );

Custom Header

This feature enables Custom_Headers support for a theme as of Version 3.4.

add_theme_support( 'custom-header' );

Note that you can add default arguments using:

$defaults = array(
	'default-image'          => '',
	'random-default'         => false,
	'width'                  => 0,
	'height'                 => 0,
	'flex-height'            => false,
	'flex-width'             => false,
	'default-text-color'     => '',
	'header-text'            => true,
	'uploads'                => true,
	'wp-head-callback'       => '',
	'admin-head-callback'    => '',
	'admin-preview-callback' => '',
);
add_theme_support( 'custom-header', $defaults );

This feature, first introduced in Version_4.5, enables Theme_Logo support for a theme.

add_theme_support( 'custom-logo' );

Note that you can add default arguments using:

add_theme_support( 'custom-logo', array(
	'height'      => 100,
	'width'       => 400,
	'flex-height' => true,
	'flex-width'  => true,
	'header-text' => array( 'site-title', 'site-description' ),
) );

Feed Links

This feature enables Automatic Feed Links for post and comment in the head. This should be used in place of the deprecated automatic_feed_links() function. This feature became available with Version 3.0.

add_theme_support( 'automatic-feed-links' );

HTML5

This feature allows the use of HTML5 markup for the search forms, comment forms, comment lists, gallery, and caption. This feature became available with Version 3.6.

add_theme_support( 'html5', array( 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption' ) );

Title Tag

This feature enables plugins and themes to manage the document title tag. This should be used in place of wp_title() function. This feature became available with Version 4.1.

add_theme_support( 'title-tag' );

Customize Selective Refresh Widgets

This feature enables Selective Refresh for Widgets being managed within the Customizer. This feature became available with Version 4.5. For more on why and how Selective Refresh works read Implementing Selective Refresh Support for Widgets.

add_theme_support( 'customize-selective-refresh-widgets' );

Multisite

To show the "Featured Image" meta box in multisite installation, make sure you update the allowed upload file types, in Network Admin, Network Admin Settings SubPanel#Upload_Settings, Media upload buttons options. Default is jpg jpeg png gif mp3 mov avi wmv midi mid pdf.

Notes

The following parameters are read only, and should only be used in the context of current_theme_supports():

Changelog

  • 4.5: Added 'customize-selective-refresh-widgets' feature.
  • 4.1: Added 'title-tag' feature.
  • 3.9: The 'html5' accepts 'gallery' and 'caption'
  • 3.6: Added 'html5' feature.
  • 3.4: Added 'custom-background' and deprecated add_custom_background().
  • 3.4: Added 'custom-header' and deprecated add_custom_image_header().
  • 3.1: Added 'post-formats'.(Ticket #14746)
  • 3.0: Added 'automatic-feed-links' and deprecated automatic_feed_links().
  • 2.9: Introduced with 'post-thumbnails' feature.

Source File

add_theme_support() is located in wp-includes/theme.php.

External Resources

Related

Theme Support: add_theme_support(), remove_theme_support(), current_theme_supports()
Theme Features: sidebar, menus, post-formats, title-tag, custom-background, custom-header, custom-logo, post-thumbnails, automatic-feed-links, html5, editor-style, content_width

See also index of Function Reference and index of Template Tags.