Last active
October 10, 2017 11:51
-
-
Save svebal/32f08ca07b737a76e224e107466d983f to your computer and use it in GitHub Desktop.
[WordPress] adding custom css classes to body or posts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* to body of one page | |
* https://developer.wordpress.org/reference/functions/body_class/ | |
**/ | |
function svebal_custom_body_class_v1( $classes ) { | |
if ( is_page( 'page-1' ) ) { | |
$classes[] = 'own-class'; | |
} | |
return $classes; | |
} | |
add_filter( 'body_class', 'svebal_custom_body_class_v1' ); | |
/** to body of more pages **/ | |
function svebal_custom_body_class_v2( $classes ) { | |
if( is_page( array( 'page-1', 'page-2', 'page-2' ) ) ) { | |
$classes[] = 'own-class'; | |
} | |
return $classes; | |
} | |
add_filter( 'body_class', 'svebal_custom_body_class_v2' ); | |
/** | |
* to a post | |
* https://developer.wordpress.org/reference/functions/post_class/ | |
**/ | |
function svebal_custom_post_class( $classes ) { | |
if( is_page( 'page-1' ) ) { | |
$classes[] = 'own-class'; | |
} | |
return $classes; | |
} | |
add_filter( 'post_class', 'svebal_custom_post_class' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment