Last active
May 29, 2020 18:59
-
-
Save maheshwaghmare/f5953ba828a862108d2fd2e5f7989377 to your computer and use it in GitHub Desktop.
Add / Remove classes from the body_class or post_class
This file contains hidden or 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 | |
| function wpse15850_body_class( $wp_classes, $extra_classes ) | |
| { | |
| // List of the only WP generated classes allowed | |
| $whitelist = array( 'home', 'blog', 'archive', 'single', 'category', 'tag', 'error404', 'logged-in', 'admin-bar' ); | |
| // List of the only WP generated classes that are not allowed | |
| $blacklist = array( 'home', 'blog', 'archive', 'single', 'category', 'tag', 'error404', 'logged-in', 'admin-bar' ); | |
| // Filter the body classes | |
| // Whitelist result: (comment if you want to whitelist classes) | |
| $wp_classes = array_intersect( $wp_classes, $whitelist ); | |
| // Blacklist result: (uncomment if you want to blacklist classes) | |
| // $wp_classes = array_diff( $wp_classes, $blacklist ); | |
| // Add the extra classes back untouched | |
| return array_merge( $wp_classes, (array) $extra_classes ); | |
| } | |
| add_filter( 'body_class', 'wpse15850_body_class', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment