Note that you must always return the classes in your callback.
So move this part:
return $classes;
out of the if
condition.
The is_page()
does support multiple ID’s when it’s in an array.
This should work:
add_filter( 'body_class', 'custom_body_class' );
function custom_body_class( $classes ) {
if ( is_page( [ 38034, 10883, 12031 ] ) ) {
$classes[] = 'new-class';
}
return $classes;
}
Related Posts:
- body_class not working anymore?
- How to use a custom body_class as a condition?
- add_filter ‘body_class’ only working for logged in users
- Remove body class per page template
- Add parent ID to body_class
- Add post class to the TinyMCE iframe?
- Adding a body class with ACF
- Remove and add class with body_class() function
- How to assign a class to a page with a custom template?
- Adding body class to login page?
- Add class to woocommerce checkout body based on filter [closed]
- Why isn’t is_page_template() adding a body class?
- body_class filter – Is there a better way to write this code?
- I am adding a new class to my body tag if the logged in user is subscriber, need help
- De-bloating the page classes
- category hierarchy level as a body class – parent cat =1, child cat=2, grandchild=3
- Add category to body class
- WordPress php filter admin_body_class not working
- Handling Body class based on Template
- create a page which displays a list of categories title+ short description?
- Remove Body Classes
- How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
- Add content as soon starts
- Append class to posts page
- body_class REST field in WP-API
- Add a unique class to HTML tag/element
- how to remove all body classes in wordpress
- Add a searchbox to the body of a page
- Need to put a script above tag in header.php – WP 5.7.1
- Add term of current custom post type to admin body class using admin_body_class
- Cannot set property ‘className’ of null at setThemeFromCookie
- How do I add Category Body Classes to Admin?
- How to add order status class to the body tag?
- Add class to website based on post taxonomy
- Add a class with body_class to a specific url with parameter
- post body class for current user only if they are the post author
- body_class(); not working with bootstrap navbar fixed top?
- Adding theme option values as custom body class
- WordPress blog assign unqiue body class
- Why does admin_body_class not work?
- How to override Plugin javascript function : $(‘body’).on(‘change’,’.class’)
- How to insert the current user’s role into the body class in the admin backend
- Add top parent page id to body class
- Adding Custom Body Class for Page: Shop
- Adding body class in author page for custom role
- add class to all images inside the content
- Body class to each level of a hierarchical custom taxonomy
- Adding body class to html tag that already has language attrubutes?
- Update body class based on theme as well as a html attribute
- How do i add a unique body class to the wordpress dashboard’s home page?
- Add post id as body class in wordpress admin dashboard [duplicate]
- Add class when more page is visited
- Creating custom post-listing templates in twentyseventeen child theme
- different body classes for each category
- add css to only body text
- mu-plugins body_class filter not working
- Calling body_class and wp_nav_menu for a different post
- adding a custom time class to in theme twenty sixteen
- How to list out all values from the get_body_class array
- Custom Taxonomies in body class with parent slug
- two body tags on all WP pages regardless of theme
- Non Object Notice Error – How to fix please
- Change body_class() PAGE to HOME
- body class according to number of published custom posts