From 7ef179bf3d4c0278ac91aa9da21640b019a1cf60 Mon Sep 17 00:00:00 2001 From: Frankline Ako <134519512+roytfrank@users.noreply.github.com> Date: Mon, 17 Jul 2023 16:18:42 -0400 Subject: [PATCH] #308 Add page slug to body tag classes --- functions.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/functions.php b/functions.php index 5ab3fe1e..41916c05 100755 --- a/functions.php +++ b/functions.php @@ -775,6 +775,21 @@ function responsive_branding_copyright() { add_action( 'r_after_footer_menus', 'responsive_branding_copyright' ); +/** + * Add slug of page as a class to body tag + */ +function r_add_page_slug_to_body_tag_classes( $classes ) { + $post = get_post(); + $classes_type = is_array( $classes ) ? true : false; + + if ( $post && $classes_type && ! in_array( $post->post_name, $classes, true ) ) { + array_push( $classes, $post->post_name ); + } + + return $classes; +} +add_filter( 'body_class', 'r_add_page_slug_to_body_tag_classes' ); + // add_filter( 'theme_page_templates', 'r_remove_news_template', 10, 3 ); /** * Admin.