Skip to content

Instantly share code, notes, and snippets.

@lmartins
Forked from studiopress/category-1.php
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmartins/0f499f3041dd3cdbfb45 to your computer and use it in GitHub Desktop.
Save lmartins/0f499f3041dd3cdbfb45 to your computer and use it in GitHub Desktop.
Conditionally add classes to the body tag
<?php
//* Do NOT include the opening php tag
//* 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;
}
<?php
//* Do NOT include the opening php tag
//* 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;
}
<?php
//* Do NOT include the opening php tag
//* Add custom body class to the head
add_filter( 'body_class', 'sp_body_class' );
function sp_body_class( $classes ) {
$classes[] = 'custom-class';
return $classes;
}
<?php
//* Do NOT include the opening php tag
//* 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;
}
<?php
//* Do NOT include the opening php tag
//* 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;
}
<?php
//* Do NOT include the opening php tag
//* 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;
}
<?php
//* Do NOT include the opening php tag
//* Add custom body class to the head
add_filter( 'body_class', 'sp_body_class' );
function sp_body_class( $classes ) {
if ( is_tag( 'sample-tag' ) )
$classes[] = 'custom-class';
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment