From 93bc039d2a59f69d6c247185d515f93c14192f10 Mon Sep 17 00:00:00 2001 From: Carolina Nymark Date: Fri, 3 Jan 2025 04:56:30 +0100 Subject: [PATCH] Add a body class for singular theme templates Themes: Add wp-singular to the list of body classes when viewing a single post object. wp-singular includes a wp prefix to reduce conflicts with existing classes. Updates test_singular_body_classes in Tests_Post_GetBodyClass to include the new CSS class. --- src/wp-includes/post-template.php | 2 ++ tests/phpunit/tests/post/getBodyClass.php | 1 + 2 files changed, 3 insertions(+) diff --git a/src/wp-includes/post-template.php b/src/wp-includes/post-template.php index 4f3bfbef0cd7e..8b84b86702931 100644 --- a/src/wp-includes/post-template.php +++ b/src/wp-includes/post-template.php @@ -676,6 +676,8 @@ function get_body_class( $css_class = '' ) { $post_id = $post->ID; $post_type = $post->post_type; + $classes[] = 'wp-singular'; + if ( is_page_template() ) { $classes[] = "{$post_type}-template"; diff --git a/tests/phpunit/tests/post/getBodyClass.php b/tests/phpunit/tests/post/getBodyClass.php index 25810e6075740..6027fc3a075da 100644 --- a/tests/phpunit/tests/post/getBodyClass.php +++ b/tests/phpunit/tests/post/getBodyClass.php @@ -105,6 +105,7 @@ public function test_singular_body_classes() { $this->assertContains( 'single-post', $class ); $this->assertContains( "postid-{$post_id}", $class ); $this->assertContains( 'single-format-standard', $class ); + $this->assertContains( 'wp-singular', $class ); } public function test_page_template_body_classes_no_template() {