Your cart is currently empty!
Unless otherwise indicated, the code snippets you see below should be placed into your theme’s functions.php file.
Include a body class for all pages on your website:
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Add custom body class to the head
add_filter( 'body_class', 'sp_body_class' );
function sp_body_class( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
Add body class to a page with a slug of ‘sample-page’:
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Add custom body class to the head
add_filter( 'body_class', 'sp_body_class' );
function sp_body_class( $classes ) {
if ( is_page( 'sample-page' ) )
$classes[] = 'custom-class';
return $classes;
}
Add body class to a page with an ID of 1:
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Add custom body class to the head
add_filter( 'body_class', 'sp_body_class' );
function sp_body_class( $classes ) {
if ( is_page( '1' ) )
$classes[] = 'custom-class';
return $classes;
}
Add body class to a category page with a slug of ‘sample-category’:
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Add custom body class to the head
add_filter( 'body_class', 'sp_body_class' );
function sp_body_class( $classes ) {
if ( is_category( 'sample-category' ) )
$classes[] = 'custom-class';
return $classes;
}
Add body class to a category page with an ID of 1:
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Add custom body class to the head
add_filter( 'body_class', 'sp_body_class' );
function sp_body_class( $classes ) {
if ( is_category( '1' ) )
$classes[] = 'custom-class';
return $classes;
}
Add body class to a tag page with a slug of ‘sample-tag’:
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Add custom body class
add_filter( 'body_class', 'sp_body_class' );
function sp_body_class( $classes ) {
if ( is_tag( 'sample-tag' ) )
$classes[] = 'custom-class';
return $classes;
}
Add body class to a tag page with an ID of 1:
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Add custom body class to the head
add_filter( 'body_class', 'sp_body_class' );
function sp_body_class( $classes ) {
if ( is_tag( '1' ) )
$classes[] = 'custom-class';
return $classes;
}