Skip to content

Instantly share code, notes, and snippets.

@roelven
Created November 28, 2010 10:47
Show Gist options
  • Save roelven/718811 to your computer and use it in GitHub Desktop.
Save roelven/718811 to your computer and use it in GitHub Desktop.
Print the sanitized page title as #id in the body tag:
//
// 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