Make WordPress Core

Opened 17 months ago

Last modified 16 months ago

#57420 new enhancement

Add filter for wp_theme_get_element_class_name

Reported by: benjgrolleau's profile benjgrolleau Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version:
Component: Editor Keywords: has-patch
Focuses: Cc:



I think it would be a good idea to add a filter to the wp_theme_get_element_class_name or WP_Theme_JSON::get_element_class_name function return. This would allow to add classes programmatically to the elements.

It could be something like that :

public static function get_element_class_name( $element ) {
        $class_name = '';

        if ( array_key_exists( $element, static::__EXPERIMENTAL_ELEMENT_CLASS_NAMES ) ) {
                $class_name = static::__EXPERIMENTAL_ELEMENT_CLASS_NAMES[ $element ];

        return apply_filters( "element_{$element}class_name", $class_name );

        // Or another option, without dynamic part.
        return apply_filters( "element_class_name", $class_name, $element );


Have a nice day.

Attachments (1)

57420.diff (453 bytes) - added by benjgrolleau 16 months ago.

Download all attachments as: .zip

Change History (3)

#1 in reply to: ↑ description @benjgrolleau
17 months ago

I've made a mistake, there's a missing underscore the filter could be :

return apply_filters( "element_{$element}_class_name", $class_name );

16 months ago

#2 @benjgrolleau
16 months ago

  • Keywords has-patch added

I've add a patch using the following solution, that seems more evolutive.

return apply_filters( "element_class_name", $class_name, $element );
Note: See TracTickets for help on using tickets.