Adding Custom Body Class for Page: Shop

you could try to use this: add_filter(‘body_class’, ‘custom_body_class’); function custom_body_class($classes) { global $post; if ($post->ID == 346) { $classes[] = ‘services’; } return $classes; } This can be used anywhere as its pulling the global variable first.

Add top parent page id to body class

found it: add_filter( ‘body_class’, ‘dc_parent_body_class’ ); function dc_parent_body_class( $classes ) { if( is_page() ) { $parents = get_post_ancestors( get_the_ID() ); $id = ($parents) ? $parents[count($parents)-1]: get_the_ID(); if ($id) { $classes[] = ‘top-parent-‘ . $id; } else { $classes[] = ‘top-parent-‘ . get_the_ID(); } } return $classes; }

Why does admin_body_class not work?

This works for the admin backend; I needed to restructure the filter to be able to add a priority: function add_admin_body_class($classes) { $user = wp_get_current_user(); foreach ($user->roles as $user_role) { $classes .= ” role-{$user_role}”; } return $classes; } add_filter(“admin_body_class”, “add_admin_body_class”, 9999);

Adding theme option values as custom body class

Review how the variable scope works.. Let’s not add yet another global variable, instead we can e.g. fetch the option values within the filter’s callback: function wpse251261_custom_body_classes( $classes ) { // Get option values $rounded_corner_radio = of_get_option( ’rounded_corner_radio’ ); $gradient_radio = of_get_option( ‘gradient_radio’ ); // Assign new body classes $classes[] = esc_attr( $rounded_corner_radio ); $classes[] … Read more