Using WordPress ‘add_theme_support()’ PHP function

The add_theme_support() WordPress PHP function registers theme support for a given feature. It must be called in the theme’s functions.php file to work. If attached to a hook, it should be ‘after_setup_theme’. The ‘init’ hook may be too late for some features.

Usage

add_theme_support( 'title-tag' );
add_theme_support( 'custom-logo', array( 'height' => 480, 'width' => 720 ) );

In the example above, the function is used to add support for ‘title-tag’ and ‘custom-logo’ features.

Parameters

  • $feature (string) (Required): The feature being added. Some examples include: ‘admin-bar’, ‘align-wide’, ‘automatic-feed-links’, ‘core-block-patterns’, ‘custom-background’, ‘custom-header’, ‘custom-line-height’, ‘custom-logo’ and so on.
  • $args (mixed) (Optional): Optional extra arguments to pass along with certain features.

More information

See WordPress Developer Resources: add_theme_support()

  • This function should be used after the ‘after_setup_theme’ hook.
  • To check if a certain theme support feature is enabled, use get_theme_support()

Examples

Add support for post thumbnails

add_theme_support( 'post-thumbnails' );

This enables featured image support for posts.

add_theme_support( 'custom-logo', array(
    'height'      => 100,
    'width'       => 400,
    'flex-width' => true,
    'flex-height' => true,
));

This enables support for custom logo with specified height and width.

Add support for HTML5 markup

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

This enables HTML5 markup for the listed forms.

Add support for starter content

add_theme_support( 'starter-content', array(
    'posts' => array(
        'home',
        'about' => array(
            'thumbnail' => '{{image-coffee}}',
        ),
    ),
));

This adds support for starter content, with a home page and an about page that uses a coffee image as the thumbnail.

Remove block editor widget support

remove_theme_support( 'widgets-block-editor' );

This deactivates the new block editor widget and reactivates the old editor widget.