Codex

Function Reference/add theme support

Contents

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 a hook.

If attached to a hook, it must be after_setup_theme. The init hook may be too late for some features.

Usage

<?php add_theme_support$feature ); ?>

Parameters

$feature
(string) (required) Name for the feature being added.
Default: None

Features list:

Addable Features

Post Thumbnails

This feature enables post-thumbnail support for a Theme. This 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');

To enable only for Posts:

add_theme_support( 'post-thumbnails', array( 'post' ) );

Or only Pages:

add_theme_support( 'post-thumbnails', array( 'page' ) );

Enable for Posts and "movie" post type but not for Pages.

add_theme_support( 'post-thumbnails', array( 'post', 'movie' ) );

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.

Using Thumbnails

Displaying thumbnails:

// in your theme index.php or single.php or custom templates
the_post_thumbnail();

Check if there is a post thumbnail assigned to the post before displaying it.

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

Feed Links

This feature enables post and comment RSS feed links to head. This should be used in place of the deprecated automatic_feed_links. This feature became available with Version 3.0.

add_theme_support( 'automatic-feed-links' );

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 you want:

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

For a list of supported formats see Post Formats

Using Formats

Check if there is a 'quote' post format assigned to the post.

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

Admin Bar

Multisite

To show the "Featured Image" meta box in mulsite 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 off.

Notes

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

Changelog

  • 3.1: Added 'post-formats'. (Ticket #14746)
  • 3.0: Added 'automatic-feed-links' feature, which was previously a separate function.
  • 2.9: Introduced with 'post-thumbnails' feature.

Source File

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

Related

Theme Support: add_theme_support(), remove_theme_support(), current_theme_supports() add_editor_style()
Theme Features: Post Thumbnails, Navigation Menus, Widgets API, Post Formats, Custom Backgrounds, Custom Headers

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