How to Add Custom Body Class

Below is the code to add body class to all pages on your site:

/** Add custom body class to the head */
add_filter( 'body_class', 'add_body_class' );
function add_body_class( $classes ) {
   $classes[] = 'custom-class';
   return $classes;
}

Below is the code to add body class to a page with a slug of ‘sample’

/** Add custom body class to the head */
add_filter( 'body_class', 'add_body_class' );
function add_body_class( $classes ) {
	if ( is_page( 'sample' ))
	$classes[] = 'custom-class';
	return $classes;
}

Below is the code to add body class to a page with an ID of 1

/** Add custom body class to the head */
add_filter( 'body_class', 'add_body_class' );
function add_body_class( $classes ) {
	if ( is_page( '1' ))
	$classes[] = 'custom-class';
	return $classes;
}

Below is the code to add body class to a category page with a slug of ‘custom-category’

/** Add custom body class to the head */
add_filter( 'body_class', 'add_body_class' );
function add_body_class( $classes ) {
	if ( is_category( 'custom-category' ))
	$classes[] = 'custom-class';
	return $classes;
}

Below is the code to add body class to a category page with an ID of 1

/** Add custom body class to the head */
add_filter( 'body_class', 'add_body_class' );
function add_body_class( $classes ) {
	if ( is_category( '1' ))
	$classes[] = 'custom-class';
	return $classes;
}

Below is the code to add body class to a tag page with a slug of ‘custom-tag’

/** Add custom body class to the head */
add_filter( 'body_class', 'add_body_class' );
function add_body_class( $classes ) {
	if ( is_tag( 'custom-tag' ))
	$classes[] = 'custom-class';
	return $classes;
}

Below is the code to add body class to a tag page with an ID of 1

/** Add custom body class to the head */
add_filter( 'body_class', 'add_body_class' );
function add_body_class( $classes ) {
	if ( is_tag( '1' ))
	$classes[] = 'custom-class';
	return $classes;
}