Last active
May 17, 2019 15:27
-
-
Save tmort/4c14cead10354b296510f789de4fd0b5 to your computer and use it in GitHub Desktop.
WordPress custom class per page based on object name.
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 | |
add_filter('body_class', 'sf3_custom_body_class'); | |
function sf3_custom_body_class($classes){ | |
global $post; | |
$prefix = 'cpgname_'; //insert your own prefix | |
if(isset($post->post_type)){ //if a post-type is required | |
$prefix .= sprintf('%s_%s', $prefix, $post->post_type); | |
// 'cpgname_page' | |
} | |
if(isset($post->post_name)){ | |
$classes[] = sprintf('%s_%s', $prefix, $post->post_name); | |
// 'cpgname_page_contact-us' | |
} | |
return $classes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment