Theme Support Generator
Generate the after_setup_theme block: the add_theme_support() calls a theme needs, the HTML5 list, the custom logo arguments and any extra image sizes.
<?php
/**
* Theme setup.
*/
/**
* Declares what the theme supports.
*
* Everything here runs on after_setup_theme, which is the first hook where the
* theme exists and the last one before WordPress starts acting on it.
*/
function my_theme_setup() {
load_theme_textdomain( 'my-theme', get_template_directory() . '/languages' );
// WordPress prints the title tag. Never hardcode one in header.php.
add_theme_support( 'title-tag' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'html5', array_map( 'trim', explode( ',', 'search-form, comment-form, comment-list, gallery, caption, style, script' ) ) );
add_theme_support(
'custom-logo',
array(
'width' => 240,
'height' => 80,
'flex-width' => true,
'flex-height' => true,
)
);
add_theme_support( 'responsive-embeds' );
add_theme_support( 'align-wide' );
add_theme_support( 'editor-styles' );
add_editor_style( 'assets/css/editor.css' );
}
add_action( 'after_setup_theme', 'my_theme_setup' );
Output is valid and updates as you type.
Fix the highlighted fields to update the output.
Tick what the theme supports and the generator writes the whole after_setup_theme block: the add_theme_support() calls, the HTML5 list, the logo arguments and any extra image sizes.
How to use
- Leave the title tag on. WordPress has printed it since 4.1, and a hardcoded
<title>inheader.phpoverrides every SEO plugin on the site. - Keep featured images on unless the theme genuinely never shows one. Without it the panel is missing from the editor and editors assume something is broken.
- Add image sizes only for the sizes the theme uses. Each one is another file written on every upload, and they are not removed when you change your mind.
- Point the editor stylesheet at a real file inside the theme. A missing file fails quietly and the editor keeps the default styles.
- Paste the block into
functions.php. It hooks itself toafter_setup_theme.
Example
A classic theme with a logo, editor styles and one extra size:
function acme_setup() {
load_theme_textdomain( 'acme', get_template_directory() . '/languages' );
add_theme_support( 'title-tag' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'html5', array_map( 'trim', explode( ',', 'search-form, comment-form, gallery, caption' ) ) );
add_theme_support(
'custom-logo',
array(
'width' => 240,
'height' => 80,
'flex-width' => true,
'flex-height' => true,
)
);
add_theme_support( 'editor-styles' );
add_editor_style( 'assets/css/editor.css' );
add_image_size( 'card-thumb', 480, 320, true );
}
add_action( 'after_setup_theme', 'acme_setup' );
add_image_size() only affects uploads made after it exists. Images already in the library keep the sizes they had.
Pitfalls
add_theme_support()on the wrong hook does nothing.after_setup_themeis the one;initis already too late for several features.- Adding an image size does not regenerate existing images. Old uploads fall back to the nearest size, which is usually the full one.
- Every registered size multiplies upload time and disk use. Five extra sizes on a photo heavy site is a real bill.
add_editor_style()takes a path relative to the theme. An absolute URL is ignored, and so is a file that does not exist.- Declaring
title-tagwhileheader.phpstill prints its own gives you two title tags, and search engines read the first. - A child theme’s
after_setup_themeruns after the parent’s, so parent support is already in place. Removing it needsremove_theme_support(). custom-logowithout flex dimensions makes WordPress offer to crop every logo. Most people want flexible dimensions and a max size.- Block themes declare most of this in
theme.json. Calling both is not an error, buttheme.jsonwins where they overlap.
Compatibility
add_theme_support() has been in WordPress since 2.9. title-tag needs 4.1, responsive-embeds and align-wide need 5.0, editor-styles needs 5.0, and appearance-tools needs 6.0. Features your version does not know about are ignored rather than fatal. The generated code targets PHP 7.0 and up, and the tool runs entirely in your browser.
Frequently asked questions
Do I still need this in a block theme?
theme.json covers alignment, spacing and colours. post-thumbnails and the text domain are still worth declaring.Why is my new image size not used?
Should I use appearance-tools?
Where does the text domain have to match?
.mo files in /languages must use the same string.