Created
December 28, 2014 10:26
-
-
Save ginocremer/88865c09053d26cd6208 to your computer and use it in GitHub Desktop.
In vielen Fällen kann eine Klasse auf dem Body-Element nützlich sein. Zum Beispiel wenn Sie jeder einzelnen Seite eine eigene Farbgebung via CSS spendieren möchten.
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
function add_top_parent_body_class( $classes ) { | |
if(is_page()): | |
$top_id = ''; | |
$ancestors = get_ancestors(get_the_ID(),'page'); | |
if ( !empty($ancestors)): | |
$top_id = end($ancestors); | |
$classes[] = 'top-parent-'.sanitize_title(get_the_title($top_id)); | |
else: | |
$classes[] = 'top-parent-'.sanitize_title(get_the_title(get_the_ID())); | |
endif; | |
else: | |
$classes[] = 'no-top-parent'; | |
endif; | |
return $classes; | |
} | |
add_filter( 'body_class', 'add_top_parent_body_class' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment