Questions tagged [body-class]

The `body_class` is a function that is meant to add classes to the body of a page, depending on the features of that page.

Filter by
Sorted by
Tagged with
1 vote
1 answer
20 views

Remove Body Classes

I need to remove specific body classes added as a comma separated delimited list to a custom field input field like this wp-custom-logo, single-post, postid-28, single-format-standard, logged-in, ...
0 votes
1 answer
34 views

Why does admin_body_class not work?

I'm trying to add the body class of the current user role to both the frontend and the admin backend. Why does admin_body_class not work for admin? The comment to this question does not work: How to ...
0 votes
0 answers
190 views

How to override Plugin javascript function : $('body').on('change','.class')

EDITED: Extensively rewritten after some research Requirement I need to override a script in the custom.js of a 3rd party plugin. $('body').on('change', '.wpt_row input.input-text.qty.text', function()...
  • 11
0 votes
0 answers
32 views

How to insert the current user's role into the body class in the admin backend

I've tried updating this code from body_class to admin_body_class but it's not inserting the .role-author into the back end body class like it did with the front end body class... i'm guessing it's ...
  • 976
1 vote
0 answers
11 views

How to add seperate classes to no-search-result and found-search-result pages on wordrpess search - is_search()

I want to add seperate body classes for no search result and found search result pages on wordrpess search. I used that code but it isn't working - > what's the error here and what is the solution ...
0 votes
2 answers
280 views

how to remove all body classes in wordpress

i am working on custom page templates. so i want to remove all body classes by one function only. i searched it for on net but not found any solution. is there anyone who can answer it. @Php Edit.. ...
's user avatar
0 votes
2 answers
51 views

Add a searchbox to the body of a page

I'm creating a website in which I need that, when I click on one of the tabs of the specific menu, and it opens, this page contains a search box in its body. My question is how can I add this search ...
0 votes
0 answers
17 views

add_filter 'body_class' only working for logged in users

The below code works fine for logged in users but not for non logged in users. How do I make it work regardless of user type? add_filter( 'body_class', 'custom_body_class' ); function ...
0 votes
1 answer
92 views

Need to put a script above </body> tag in header.php - WP 5.7.1

I need to put this script above the tag in the header.php. window.Futy = { key: '0000000000' }; (function (e, t) { var n = e.createElement(t); n.async = true; n.src = 'https://v1.widget....
  • 1
0 votes
3 answers
337 views

Add class to woocommerce checkout body based on filter [closed]

I am trying to add a class to a checkout page if the checkout contains a subscription renewal. Woocommerce provides wcs_cart_contains_renewal() to check. I am using this code but obviously missing ...
  • 95
0 votes
1 answer
37 views

How to add order status class to the body tag?

do you know how can we add CSS class into the body tag when a user has an (any) order which is on pending payment status? I tried this one but no luck add_filter( 'body_class', 'order_class'); ...
0 votes
2 answers
129 views

Add term of current custom post type to admin body class using admin_body_class

I am trying to add the current custom post type term to the body class of my WordPress admin page. So when I am viewing an existing custom post type that has been assigned a term it will add that ...
0 votes
1 answer
316 views

Add top parent page id to body class

I need to have the top parent page id added to the body class of the pages. Homepage (id:10) - Sub page (id:11) -- Sub detail page (id:12) By default it's like: Sub page gets parent Id 10 in the ...
  • 113
0 votes
2 answers
679 views

Add class to website based on post taxonomy

I want to write a class to the body of all pages posts and custom posts (IE entire site) I am using a front end editor that allows logged in users to edit posts and keep them out of the back-end. I ...
  • 33
0 votes
1 answer
936 views

Add a class with body_class to a specific url with parameter

i try to add a class to the body for a specific page/url, which has a parameter at the end. the url looks like this: https://sample-site.com/user/37/?um_action=edit with my code, the class is also ...
0 votes
1 answer
55 views

post body class for current user only if they are the post author

I'm trying to find a way to add a body class "author" IF the current user is the author of the post they are viewing. This is what I have so far... add_filter( 'body_class','my_body_classes' ); ...
  • 976
0 votes
2 answers
365 views

Adding Custom Body Class for Page: Shop

been hacking at this for some time and haven't been able to make much progress. The goal is to add a custom body class to a specific page. -I know there are a few answered posts on this topic, and ...
1 vote
1 answer
1k views

Adding body class to login page?

I can't figure out for the life of me how to add a custom body class to the WordPress login page. I found this thread, which suggests using the admin_body_class along with this one to check if the ...
  • 217
0 votes
2 answers
5k views

Cannot set property 'className' of null at setThemeFromCookie

I am coding in WordPress to make a button to toggle body class from light-mode to dark-mode. i was experimenting with trying to add a cookie so that the preference is remembered for the browser. But i ...
's user avatar
0 votes
0 answers
150 views

Adding body class in author page for custom role

I am trying to add a unique body class using body_class filter if the role is a custom one via my plugin. I have a custom role called trip_vendor and the url for its profile page is abc.com/operator/...
1 vote
1 answer
77 views

Handling Body class based on Template

Through a PHP function, I think I can handle body class, but I think WordPress would have some specific way to handle it. If Home.php then class in the body should be wbody else it should be bgody. ...
0 votes
1 answer
619 views

add class to all images inside the content

I have a function like this : function add_responsive_class($content) { $content = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8"); if (!empty($content)) { $document = new ...
's user avatar
0 votes
1 answer
148 views

Body class to each level of a hierarchical custom taxonomy

How would this be adapted to apply to specific custom taxonomies? add_filter( 'body_class', 'custom_cat_archiev_class' ); function custom_cat_archiev_class( $classes ) { if ( is_category() ) { ...
  • 976
0 votes
1 answer
135 views

Adding body class to html tag that already has language attrubutes?

In my theme (Underscores based). I have <html <?php language_attributes(); ?>> Then I'm calling the body class function on the body tag: <body <?php body_class(); ?>> ...
0 votes
1 answer
382 views

Update body class based on theme as well as a html attribute

I just started using wordpress. Now I'm trying to create a theme for a static web page I wrote. For that web page I'm using barbajs, which is why I have a html tag (in my case a section tag) with a ...
  • 195
0 votes
1 answer
1k views

How to use a custom body_class as a condition?

I am using a plugin that works great apart from the fact the breadcrumb is messed up. I would like to either try to ovveride the breadcrumb or remove it completely if I don't succeed. I am using ...
0 votes
1 answer
198 views

How do i add a unique body class to the wordpress dashboard's home page?

I installed a plugin that let me add my own css and html to the home page of the dashboard. This is great! However some of my styles are messing up other pages. I could solve this if the home page of ...
  • 111
1 vote
2 answers
114 views

Add content as soon <body> starts

So, what I am trying to do is creating a slideshow plugin that won't require end user to write a single line of code. I can't use custom posts because I need to keep it simple for the end user. Is ...
1 vote
2 answers
541 views

Append class to posts page

I'm trying to style something unique to the Blog/Posts page, which isn't on the front page. The body tag right now looks like this:<body <?php body_class() ?>> But doing this <body <...
0 votes
1 answer
422 views

Add post id as body class in wordpress admin dashboard [duplicate]

i am looking to add custom class names to the body tag of all our posts (including pages, posts, Woocommerce products) all have post id's (seen in the URL when editing a post, category, etc.) and is ...
  • 265
1 vote
1 answer
41 views

De-bloating the page classes

The standard page class in Wordpress looks something like this; <body class="page-template page-template-page-templates page-template-page-standard page-template-page-templatespage-standard-php ...
0 votes
2 answers
804 views

body_class(); not working with bootstrap navbar fixed top?

I am trying to use WordPress with a bootstrap template, class navbar-fixed-top is conflicting with body_class(); Is there a workaround to this problem? Edit 1: Additional details, I can't see the ...
0 votes
2 answers
159 views

Add class when more page is visited

I would like to add a CSS class to the body if a visitor goes to the second or third etc. page of the website. Or vice-versa: add a class only on the first visited page. The goal is that I can ...
0 votes
5 answers
12k views

Add a unique class to HTML tag/element

I know there is a body_class function for WordPress. But is there one (or a way) to add a class to the HTML element? My goal is to be able to add a unique class (or ID) to a page's HTML element. ...
  • 134
2 votes
1 answer
2k views

I am adding a new class to my body tag if the logged in user is subscriber, need help

Here's what I am doing right now. In my header.php file: <?php if ( current_user_can( 'subscriber' ) ){ textdomain_body_classes(); } else { ...
1 vote
2 answers
1k views

category hierarchy level as a body class - parent cat =1, child cat=2, grandchild=3

I'm finding this next to impossible to find any info on. I'm looking for a way to assign each category level a number and then add that number to the body class. e.g. the parent category archive would ...
  • 976
2 votes
2 answers
1k views

Why isn't is_page_template() adding a body class?

I want to conditionally add a body class depending on what template is being used. I can't figure out why the following code is not working... function damsonhomes_body_classes( $classes ) { if (...
0 votes
2 answers
779 views

Creating custom post-listing templates in twentyseventeen child theme

I'm using a child theme based on 'Twenty Seventeen' and have created a custom post type ('review'). I want to make two Pages, one which lists 'reviews' and the other which lists a mixture of 'posts' ...
-2 votes
2 answers
37 views

body class according to number of published custom posts

Is it possible to add a number to the body class according to how many custom posts a current user has published, e.g. CUSTOMPOST-4
  • 976
0 votes
1 answer
631 views

different body classes for each category

How can I add special classes ( like " japan japan_index" ) for body class in category-japan.php and for category.php something like this " archive archive_index " and also I'm using this code to put ...
  • 121
0 votes
2 answers
850 views

add css to only body text

In my single wordpress posts I want to apply a padding of 100px to the left and right. The problem is that when I apply it to .single .post-content the images also get a padding. However, I want all ...
0 votes
1 answer
111 views

Adding theme option values as custom body class

I'm looking to add some custom classes to the body element based on theme options. I've setup two theme options ('rounded_corner_radio' & 'gradient_radio') that successfully output their values ...
3 votes
1 answer
6k views

Remove and add class with body_class() function

I want to remove the default body class on the theme and add a new class. I use this code to do this: //REMOVE / ADD HOME CLASS FROM BODY add_filter('body_class', function (array $classes) { ...
  • 179
0 votes
0 answers
95 views

mu-plugins body_class filter not working

So this code was working fine in mu-plugins until an update back in september or so... function save_cookie_class( $classes ) { array_push( $classes, isset($_COOKIE['some_cookie']) ); ...
-1 votes
1 answer
729 views

Change body_class() PAGE to HOME

I have a static Page Template with new updated post and i need change the body class page to home, the actualy class is: page page-id-2 page-template page-template-page-update page-template-page-...
0 votes
0 answers
681 views

Remove body class per page template

I want to remove a body class based on a page template, but I want the control to be per template. My solution was create a function that removes the body class, then place that inside a function that ...
  • 488
0 votes
1 answer
140 views

Calling body_class and wp_nav_menu for a different post

I need to be able to display wp_nav_menu and body_class for a page/post that isn't the current post. For instance: // current page/post is ID:100 wp_query/query_posts{ // currently looping a ...
1 vote
0 answers
3k views

body_class not working anymore?

I always used the following code to add a class to the body element of posts. //Page Slug Body Class function add_slug_body_class( $classes ) { global $post; if ( isset( $post ) ) { $classes[] = $...
1 vote
2 answers
875 views

Add category to body class

I want to add the currenty category to the body class. How do I need to modify my current code, to add also the current category as a body class to the is_singular( 'knowledgebase' ) section? My ...
  • 111
0 votes
1 answer
102 views

adding a custom time class to <body> in theme twenty sixteen

I'm moving on from the child of a (no-longer serviced) 2009 theme to a child of twenty sixteen - I previously had a code in my functions that generated the week number as a body class - e.g w32 (for ...
  • 11