Skip to content

Consolidate add_theme_support() features into a single array #8732

Closed
@mor10

Description

Right now various Gutenberg features are enabled (and disabled) through individual add_theme_support() declarations (documentation):

add_theme_support( 'align-wide' );
add_theme_support( 'editor-color-palette', array(
    array(
        'name' => __( 'strong magenta', 'themeLangDomain' ),
        'slug' => 'strong-magenta',
        'color' => '#a156b4',
    ),
) );
add_theme_support( 'editor-font-sizes', array(
    array(
        'name' => __( 'small', 'themeLangDomain' ),
        'shortName' => __( 'S', 'themeLangDomain' ),
        'size' => 12,
        'slug' => 'small'
    ),
));
add_theme_support( 'disable-custom-colors' );
add_theme_support( 'wp-block-styles' );

This lends itself to fractured and confusing code and makes it hard for anyone reading the code to quickly identify what features are on or off. It also allows theme developers to declare support for different features in different locations throughout the template files making the supports hard to find.

Ideally these theme supports would all be declared in a single add_theme_supports() array with references to additional arrays. Something like this (though probably not like this - someone with a keener eye for PHP should propose an actual solution):

$theme_colors = array(
    array(
        'name' => __( 'strong magenta', 'themeLangDomain' ),
        'slug' => 'strong-magenta',
        'color' => '#a156b4',
    ),
);

$theme_font_sizes = array(
    array(
        'name' => __( 'small', 'themeLangDomain' ),
        'shortName' => __( 'S', 'themeLangDomain' ),
        'size' => 12,
        'slug' => 'small'
    ),
);

add_theme_support( 'block-features', array( 
    'align-wide',
    'editor-color-palette' => $theme_colors,
    'editor-font-sizes' => $theme_font_sizes,
    'disable-custom-colors',
    'wp-block-styles',
) );

Benefits

This approach clearly stipulates, in one location, what Gutenberg (block editor) features are enabled/disabled in the theme and makes control easy. It also establishes a framework for future theme support controls and makes it easy for developers to spot them if they are enabled. As a bonus, adding all the features in one location surfaces issues around naming conventions and feature descriptions. Most importantly, consolidating all these feature under one roof so to speak makes themes easier to build and maintain.

Challenges

There are some challenges which need to be addressed around this, one of which was brought up by @westonruter in #2021 around child themes and overrides.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions