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
2 votes
0 answers
39 views

How can I add classes to the Gutenberg iframe (editor-canvas) body tag? Added in WP 6.2(?)

I believe Gutenberg content was iframed in WP 6.2 if all blocks are v3. I have used a function like below to add very important custom classes to my admin body tags which in turn alters how the ...
lepardman's user avatar
  • 183
1 vote
1 answer
41 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, ...
Brad Dalton's user avatar
  • 6,896
1 vote
1 answer
188 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 ...
BlueDogRanch's user avatar
1 vote
0 answers
599 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()...
TaoRich's user avatar
  • 121
1 vote
0 answers
13 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 ...
Alex Smith's user avatar
0 votes
2 answers
691 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.. ...
user avatar
0 votes
2 answers
68 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 ...
user207483's user avatar
0 votes
0 answers
30 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 ...
Jenefer's user avatar
0 votes
1 answer
256 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....
Henno's user avatar
  • 1
0 votes
3 answers
696 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 ...
Nik's user avatar
  • 95
0 votes
1 answer
73 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'); ...
Ugur Terzi's user avatar
0 votes
2 answers
289 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 ...
moorewebx's user avatar
0 votes
1 answer
623 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 ...
n00bly's user avatar
  • 113
0 votes
2 answers
1k 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 ...
Ian S's user avatar
  • 31
0 votes
1 answer
1k 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 ...
LovinQuaQua's user avatar
0 votes
1 answer
98 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' ); ...
Pete's user avatar
  • 998
0 votes
2 answers
543 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 ...
Zach S.'s user avatar
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 ...
nickpish's user avatar
  • 217
0 votes
2 answers
6k 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 ...
user avatar
0 votes
0 answers
181 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/...
saurav.rox's user avatar
1 vote
1 answer
181 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. ...
Richa Sharma's user avatar
0 votes
1 answer
740 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 ...
user avatar
0 votes
1 answer
188 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() ) { ...
Pete's user avatar
  • 998
0 votes
1 answer
309 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(); ?>> ...
Best Dev Tutorials's user avatar
0 votes
1 answer
432 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 ...
josias's user avatar
  • 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 ...
Francois's user avatar
0 votes
1 answer
242 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 ...
Ian Garvey's user avatar
1 vote
2 answers
159 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 ...
Downloadtaky's user avatar
1 vote
2 answers
674 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 <...
Dominic Neo's user avatar
0 votes
1 answer
523 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 ...
Patrick's user avatar
  • 295
1 vote
1 answer
45 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 ...
Chris Pink's user avatar
0 votes
2 answers
819 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 ...
user5676973's user avatar
0 votes
2 answers
193 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 ...
Batyuvitez's user avatar
0 votes
5 answers
14k 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. ...
Garconis's user avatar
  • 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 { ...
Asem J Syed's user avatar
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 ...
Pete's user avatar
  • 998
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 (...
richerimage's user avatar
0 votes
2 answers
807 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' ...
Phil Gyford's user avatar
-2 votes
2 answers
38 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
Pete's user avatar
  • 998
0 votes
1 answer
641 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 ...
arata's user avatar
  • 121
0 votes
2 answers
972 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 ...
user6738171's user avatar
0 votes
1 answer
113 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 ...
Tom Perkins's user avatar
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) { ...
Crashy's user avatar
  • 199
0 votes
0 answers
119 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']) ); ...
MediaFormat's user avatar
-1 votes
1 answer
741 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-...
user3477026's user avatar
0 votes
0 answers
744 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 ...
psorensen's user avatar
  • 497
0 votes
1 answer
147 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 ...
rorymorris89's user avatar
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[] = $...
Rick Alvarez's user avatar
1 vote
2 answers
943 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 ...
JGeer's user avatar
  • 111
0 votes
1 answer
107 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 ...
billn's user avatar
  • 11