Articles of body class

How to assign a class to a page with a custom template?

I tried with the bellow code to assign a body class to a page with a custom template, but this didn’t work. What is wrong here? function prefix_conditional_body_class($classes) { if ( get_page_template_slug(get_the_ID()) === ‘mytemplate.php’ ) { $classes[] = ‘mytemplate’; } return $classes; } add_filter( ‘body_class’, ‘prefix_conditional_body_class’ ); UPDATE 2 The template is assigned to the […]

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 all the sub pages are showing the sub background except for the blog page, even the blog detail […]

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 show the class .catlevel-1, whereas the child category archive would show class .catlevel-2 … and so on.

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 nav, thet’s the main issue. I’m trying to use <?php body_class(); ?> to fix this up but no results. Here’s the code upto nav: […]

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 classes to admin with admin_body_class does work. Any ideas? function base_admin_body_class( $classes ) { // Current action […]

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 to the front-end using echo so I know they’re working. What I now need to do is insert those values into the body class but can’t work […]

How to add same body class in multiple pages using their page id?

add_filter( ‘body_class’, ‘custom_body_class’ ); function custom_body_class( $classes ) { if ( is_page( ‘38034’ ) ) { $classes[] = ‘new-class’; return $classes; } } Above code works fine to add a class in a page which id 38034. Now I want to add same class in multiple pages, how I can do that? can I write […]

body_class REST field in WP-API

I’m building a site with WP-API (v2). I’m attempting to add a REST field according to documentation that includes anything from body_class. However, body_class is returning either one class (one added by my theme) or no classes (when the condition in the theme that adds the class is false). Here’s the relevant code in my […]

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 there a hook or a filter that would let me include my php generated […]

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 <?php body_class(‘blog’) ?>> only returns <body class=”logged-in”> or just <body> if I’m not logged in. I’ve tried: <body <?php if ( is_home()) { echo […]