Themes: Add wp-theme-<name> and wp-child-theme-<name> classes to body_class.

This changeset introduces new classes to the body tag. The classes `wp-theme-<name>` and `wp-child-theme-<name>` (when the current theme is a child theme) are added, where `<name>` represents the sanitized name of the active theme.

Props cais, GaryJ, nacin, SergeyBiryukov, johnjamesjacoby, nirajgirixd, poena, audrasjb, rinkalpagdar.
Fixes #19736.




git-svn-id: https://develop.svn.wordpress.org/trunk@59698 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jb Audras 2025-01-24 10:56:38 +00:00
parent 530e8fda5d
commit 0f6707de30
2 changed files with 10 additions and 0 deletions

View File

@ -214,6 +214,11 @@ if ( $current_screen->is_block_editor() ) {
$admin_body_class .= ' block-editor-page wp-embed-responsive';
}
$admin_body_class .= ' wp-theme-' . sanitize_html_class( get_template() );
if ( is_child_theme() ) {
$admin_body_class .= ' wp-child-theme-' . sanitize_html_class( get_stylesheet() );
}
$error_get_last = error_get_last();
// Print a CSS class to make PHP errors visible.

View File

@ -838,6 +838,11 @@ function get_body_class( $css_class = '' ) {
}
}
$classes[] = 'wp-theme-' . sanitize_html_class( get_template() );
if ( is_child_theme() ) {
$classes[] = 'wp-child-theme-' . sanitize_html_class( get_stylesheet() );
}
if ( ! empty( $css_class ) ) {
if ( ! is_array( $css_class ) ) {
$css_class = preg_split( '#\s+#', $css_class );