add_theme_support(): the features every theme should declare
Many core features work only when the theme says it supports them. Without the declarations, WordPress prints no <title> tag, the editor has no featured image box, the Customizer has no logo option, and wide and full-width blocks stay at the content width. All of it is switched on with add_theme_support() in one setup function.
Problem: A custom theme has no title tag in the page source, no featured images, no custom logo option, and blocks with “Wide width” look like normal ones.
Solution: Call add_theme_support() for each feature inside a callback on after_setup_theme, which runs right after the theme’s functions.php is loaded and before init.
The setup function
<?php
add_action( 'after_setup_theme', 'ha_theme_setup' );
function ha_theme_setup() {
load_theme_textdomain( 'ha-theme', get_template_directory() . '/languages' );
// <title> printed by wp_head(); remove the hard-coded one from header.php
add_theme_support( 'title-tag' );
// Featured images, for all post types that support thumbnails
add_theme_support( 'post-thumbnails' );
// Valid HTML5 markup for core output; 'style' and 'script' (5.3+) drop the type attribute
add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'style', 'script' ) );
// Logo in the Customizer, printed with the_custom_logo()
add_theme_support( 'custom-logo', array(
'height' => 80,
'width' => 240,
'flex-height' => true,
'flex-width' => true,
) );
// RSS feed links in <head>
add_theme_support( 'automatic-feed-links' );
// Block editor
add_theme_support( 'align-wide' ); // "Wide" and "Full" alignment
add_theme_support( 'responsive-embeds' ); // embeds keep their aspect ratio
add_theme_support( 'editor-styles' ); // use the editor stylesheet below
add_editor_style( 'assets/css/editor.css' );
register_nav_menus( array( 'primary' => __( 'Primary menu', 'ha-theme' ) ) );
}
Each call is independent; declare only what the theme really supports. Wide alignment, for example, also needs CSS for .alignwide and .alignfull, otherwise the option exists in the editor but does nothing on the site.
The logo in the header
<?php
if ( has_custom_logo() ) {
the_custom_logo(); // <a href="home"><img ...></a> with the right classes
} else {
printf( '<a class="site-title" href="%s">%s</a>', esc_url( home_url( '/' ) ), esc_html( get_bloginfo( 'name' ) ) );
}
Other useful features
custom-backgroundandcustom-header: Customizer options for the background and a header image.post-formats: formats such as aside, gallery, quote; only if the templates show them differently.remove_theme_support( 'core-block-patterns' )(WordPress 5.5+): hide the core block patterns if the theme ships its own.starter-content: demo widgets, pages and menus shown in the Customizer on a fresh site.
Checking support in a plugin
<?php
if ( current_theme_supports( 'post-thumbnails' ) ) {
// safe to rely on featured images
}
Plugins that add front-end output should check support instead of assuming it, and fall back gracefully when the theme does not declare a feature.
NOTE: With title-tag declared, remove the <title> from header.php; otherwise the page has two titles. The text of the title is then changed with the document_title_parts and document_title_separator filters, which SEO plugins use too.