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
0
votes
2answers
35 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
0answers
14 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
1answer
40 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....
0
votes
3answers
64 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 ...
0
votes
1answer
30 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
2answers
22 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
0answers
31 views

<body <?php body_class(); ?> > won't change after Ajax loaded just the main content

I’m using Ajax to load only the main content of my website, as I have a music player and I don’t want it to stop playing while browsing website. Everything is working well, except that, as the body ...
0
votes
1answer
106 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 ...
0
votes
2answers
167 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 ...
0
votes
1answer
519 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
1answer
29 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' ); ...
0
votes
1answer
225 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
1answer
641 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 ...
0
votes
2answers
4k 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 ...
0
votes
0answers
111 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
1answer
47 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
1answer
374 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 ...
0
votes
1answer
116 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() ) { ...
0
votes
1answer
65 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
1answer
311 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 ...
0
votes
1answer
416 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
1answer
149 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 ...
1
vote
2answers
86 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
2answers
319 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
1answer
317 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 ...
1
vote
1answer
36 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
2answers
774 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
2answers
130 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 ...
-1
votes
5answers
9k 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. ...
2
votes
1answer
1k 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
2answers
935 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 ...
2
votes
2answers
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
2answers
722 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
2answers
35 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
0
votes
1answer
593 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 ...
0
votes
1answer
742 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
1answer
92 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
1answer
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) { ...
0
votes
0answers
77 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
1answer
633 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
0answers
599 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 ...
0
votes
1answer
131 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
0answers
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
2answers
812 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 ...
0
votes
1answer
92 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 ...
4
votes
1answer
559 views

Add post class to the TinyMCE iframe?

I want to add styles to editor-style.css, based on the category the current post belongs to. Therefore I would like to add the post classes - using get_post_class() - to the body of the TinyMCE ...
-1
votes
1answer
856 views

Non Object Notice Error - How to fix please

No doubt I'm missing something obvious here... The following code to add a body class to an admin page is producing this error notice: Notice: Trying to get property of non-object in /.../box.php on ...
0
votes
1answer
96 views

How do I add Category Body Classes to Admin?

So why are category classes not added to the admin body class with this function? I see the current post ID in page source as part of the complete body class, so the basic function of adding body ...
0
votes
1answer
178 views

Wordpress blog assign unqiue body class

I am using a function to change the body class depending on whether the user is on the home or sub page. Currently everything is working as it should, the homepage is showing the home background and ...
1
vote
1answer
720 views

Wordpress php filter admin_body_class not working

I have the following function in a plugin I have built: static function filter_add_body_classes( $body_classes ) { $new_classes = array(); // Only when logged in if ( ! ...