The my_custom_class()
function is using the class name my-custom-class
, but the CSS is targeting the class my_custom_class
. These two strings should be exactly the same:
.my-custom-class {
margin-top: 350px !important;
}
Also, it would be a little cleaner to handle all of the body_class
stuff in a single callback function:
add_action( 'body_class', 'my_custom_class');
function my_custom_class( $classes ) {
// Remove 'blog' class
if (in_array('blog', $classes)) {
unset( $classes[array_search('blog', $classes)] );
}
// Remove 'home' class
if (in_array('home', $classes)) {
unset( $classes[array_search('home', $classes)] );
}
// Add custom class
$classes[] = 'my-custom-class';
return $classes;
}
Related Posts:
- How to add classes to post_class?
- How do I add a custom body class for a specific page ID?
- Add a different class name to each sticky post?
- Alternate post_class on each post
- How to use post_class function?
- How to load post_class() locally
- post_class output in wrong area?
- Adding post_class into functions.php query
- Where to use Post class in a real theme, title, content or parent div or article tag?
- How to remove a class from a post_image div?
- How do I create a sticky sidebar?
- How to specify a class added to my gallery
- Add post class to the TinyMCE iframe?
- Category as Class for Custom Post Type
- Get parent category class in post_class()
- adding a custom css class to post
- Add class to the items in wp_list_pages
- Adding body class to login page?
- Odd/even class on article tag
- How to add padding between posts
- If Loop has odd number of posts on last page Custom style for last post in it
- Remove classes from post_class()
- Add class to woocommerce checkout body based on filter [closed]
- Adding body class when post contains a specific shortcode
- Why isn’t is_page_template() adding a body class?
- body_class filter – Is there a better way to write this code?
- WordPress Loop – Style rows of posts differently
- Indirect modification of overloaded property WP_Post::$classes has no effect
- current-menu-item class for custom post type parent
- Theme Check: Could not find post_class
- Add Post Tags to Body Class
- List of Body Classes Generated by body_class()
- De-bloating the page classes
- category hierarchy level as a body class – parent cat =1, child cat=2, grandchild=3
- Add a class to post title if a link ends with a certain extension
- How to add class or id to shortcode HTML elements?
- Output terms to post_class()
- How to make classes for posts?
- How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
- Remove Extra Classes from Post Title
- Append class to posts page
- Is it possible to store Custom Post Type data in separate set of tables and still have wp_post class functionality?
- body_class not working anymore?
- Change Post Class function
- body_class REST field in WP-API
- how to remove all body classes in wordpress
- Post classes in the loop are being changed in certain themes
- How to add same body class in multiple pages using their page id?
- Add $values to post_class()
- 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
- Every second post different class in blog view
- What Generated Classes and IDs That Is Always Used On All Themes?
- post_class not working with css
- Using post_class to style posts indivdually
- How to add order status class to the body tag?
- Add a class with body_class to a specific url with parameter
- body_class(); not working with bootstrap navbar fixed top?
- How to add post classes?
- WordPress blog assign unqiue body class
- How can I add a class to particular paragraphs in my post?
- WordPress call post-ID in jquery
- How to style posts selecting a CSS post_class (added through custom_fields?)?
- Add a class to post if it has been recently updated
- Microformats in a single post – layout conflict
- Apply Post Class to Custom Post Type
- How to get category names in post_class?
- Add a class to post_class if more than one post shares same meta_value_num
- Enclose title within a div?
- How to override Plugin javascript function : $(‘body’).on(‘change’,’.class’)
- add_filter ‘body_class’ only working for logged in users
- Set class if a meta value is set within post archive
- Add top parent page id to body class
- Correct way adding External classes to Custom Post type and output their methods to template
- adding additional class to get the post thumbnail [duplicate]
- Add all category as classes in foreach loop
- How do I use $wp_query->current_post with get_template_part? I’m trying to add post classes (first/last/even/odd) to custom loops
- add class to all images inside the content
- Update body class based on theme as well as a html attribute
- 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
- mu-plugins body_class filter not working
- get_post_class not working properly
- How to list out all values from the get_body_class array
- Add parent ID to body_class
- Custom Taxonomies in body class with parent slug
- Custom query with post_class filter using current_post not working
- Post Class for Custom Taxonomy Error
- post_type_exists keeps returning false
- WordPress Tags in class
- Help with output of post classes using apply_filters
- How to mark every 3rd post
- two body tags on all WP pages regardless of theme
- Non Object Notice Error – How to fix please
- PHP Use Declared array Variable inside already Declared Array
- Change body_class() PAGE to HOME