Add Class in Body Tag in WordPress

Add Class in Body Tag in WordPress
130 Views
<?php
add_filter( 'body_class', 'cxc_add_body_classes_call_back' );
function cxc_add_body_classes_call_back( $classes ) {

    // Adds a class if post type is Tools
	if ( is_singular('tools') ) {
		$classes[] = 'tools-single';
	}

    // Add a class if is not Home Page
	if ( ! is_home() ) {
		$classes[] = 'not-home';
	}

    // Add a class if user is Admin
	if ( current_user_can('administrator') ) {
		$classes[] = 'user-is-admin';
	}
	
	return $classes;
}
?>

Was this article helpful?
YesNo

Leave a comment

Your email address will not be published.