Articles of body class

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 page page-id-7 page-parent”> which if you ask me, is a bit bloated, I mean who is going to set up a css class .page-template-page-templatespage-standard-php ? And I do like human readable code. So my question is how to rewrite the […]

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) { if (in_array(‘home’, $classes)) { unset( $classes[array_search(‘home’, $classes)] ); } return $classes; }); add_filter(‘body_class’, function (array $classes) { if (in_array(‘blog’, $classes)) […]

Adding a body class with ACF

I have created a radio button field with ACF so that admin can specify a colour. E.g: blue : Blue pink : Pink I’d like this to be output as a class via <body <?php body_class(); ?> in header.php. Is this possible? I’m currently outputting the class in header.php like so: <div id=”page” class=”site <?php […]

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 (is_page_template(‘single.php’)) { $classes[] = ‘sans-hero’; } return $classes; } add_filter( ‘body_class’, ‘damsonhomes_body_classes’); Thanks all

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 iframe. I’ve seen this question, but it’s about adding classes via JavaScript, and I need it to be done via […]