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 mark every 3rd post
- How to specify a class added to my gallery
- Child Pages Loop
- Add post class to the TinyMCE iframe?
- Category as Class for Custom Post Type
- WordPress: How to use post_class() in an echo
- Adding a body class with ACF
- Get parent category class in post_class()
- adding a custom css class to post
- Add class to the items in wp_list_pages
- How to assign a class to a page with a custom template?
- Where should I use post_class()?
- Add filter to wp_list_categories and query what type of taxonomy-terms it use?
- 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
- How can I make wp_list_categories output li with category-slug as class, for its children?
- 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?
- I am adding a new class to my body tag if the logged in user is subscriber, need help
- 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
- Duplicate attribute class causing site validation error
- Adding class to featured image
- 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 category to body class
- WordPress php filter admin_body_class not working
- Is post_class(); going to slow WordPress page speed
- WordPress post arrangement using post_class
- Add a class to post title if a link ends with a certain extension
- Handling Body class based on Template
- Adding Filter to Homepage only
- create a page which displays a list of categories title+ short description?
- How to add class or id to shortcode HTML elements?
- different post-class when template is loaded via ajax
- Output terms to post_class()
- How to make classes for posts?
- Remove Body Classes
- How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
- add active class based on permalink and url
- Remove Extra Classes from Post Title
- Add content as soon starts
- 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 assign classes to all elements?
- Add a unique class to HTML tag/element
- how to remove all body classes in wordpress
- Post classes in the loop are being changed in certain themes
- Need help “sanitizing” a custom function that pulls category slug into body class
- How to change “post_class()” for a custom post type?
- How to add same body class in multiple pages using their page id?
- Add $values to post_class()
- post_class() breaks out of formatting. . . extra markup also generated
- 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 can i show post_class() within output loop?
- How do I add Category Body Classes to Admin?
- 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 can i remove the posts category class names from body_class
- CSS class on last post in loop ( custom query )
- 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
- How to use a custom body_class as a condition?
- body_class(); not working with bootstrap navbar fixed top?
- Adding theme option values as custom body class
- How to add post classes?
- WordPress blog assign unqiue body class
- How to edit the styles for the table of pages/post listed in the admin when you click on pages/posts?
- How can I add a class to particular paragraphs in my post?
- WordPress call post-ID in jquery