Created
August 19, 2015 11:58
-
-
Save mohsinrasool/eb28eb51a933b7e51c83 to your computer and use it in GitHub Desktop.
Add Page slug to the body_class function
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
// Add to the body_class function | |
function condensed_body_class($classes) { | |
global $post; | |
// add a class for the name of the page - later might want to remove the auto generated pageid class which isn't very useful | |
if( is_page()) { | |
$pn = $post->post_name; | |
$classes[] = "page-".$pn; | |
} | |
// add a class for the parent page name | |
if ( is_page() && $post->post_parent ) { | |
$post_parent = get_post($post->post_parent); | |
$parentSlug = $post_parent->post_name; | |
$classes[] = "parent-".$parentSlug; | |
} | |
// add class for the name of the custom template used (if any) | |
$temp = get_page_template(); | |
if ( $temp != null ) { | |
$path = pathinfo($temp); | |
$tmp = $path['filename'] . "." . $path['extension']; | |
$tn= str_replace(".php", "", $tmp); | |
$classes[] = "template-".$tn; | |
} | |
return $classes; | |
} | |
add_filter('body_class', 'condensed_body_class'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment