Created
November 28, 2010 10:47
-
-
Save roelven/718811 to your computer and use it in GitHub Desktop.
Print the sanitized page title as #id in the body tag:
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
// | |
// I don't like logic in views / template files. | |
// Here's a first attempt of nicely identifying your pages by page titles. | |
// | |
// Yes, I know Wordpress' body_class() does something similar, | |
// but I like semantics and readable code. | |
// | |
// Put this in your functions.php: | |
// Print the sanitized page title as #id in the body tag: | |
function rv_body_id() { | |
$title = get_the_title($post->post_parent); | |
// When not on PHP5.3, replace filter_var with a wp function to sanitize: | |
$result = 'id="wp_'.strtolower(sanitize_title($title)).'" '; | |
return $result; | |
} | |
// Use in your template files: | |
// <body <?php print rv_body_id(); ?>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment