Created
March 10, 2015 16:59
-
-
Save matesnippets/8bf6d23d0ee10ebff13b to your computer and use it in GitHub Desktop.
PHP, WordPress, Prepend a namespace in WordPress body_class() function, so that it won't clash with other class names. E.g. `root--`.
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
| /** | |
| * Prepend a namespace in WordPress body_class() function | |
| * @param string $prefix The desired prefix | |
| * @param string $classes Additional classes separated by single space | |
| * @return string Single space separated list of classes | |
| */ | |
| function body_class_prefix($prefix, $classes = '') | |
| { | |
| global $wp_query; | |
| $output = ''; | |
| $body_classes = get_body_class(); | |
| foreach ($body_classes as $class) { | |
| $output .= $prefix.$class . ' '; | |
| } | |
| echo "class='$output$classes' "; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the code! I made it into a filter: