Skip to content

Instantly share code, notes, and snippets.

@jeremyboggs
Created April 9, 2012 14:55
Show Gist options
  • Save jeremyboggs/2344038 to your computer and use it in GitHub Desktop.
Save jeremyboggs/2344038 to your computer and use it in GitHub Desktop.
Adds post title as a value to WP's body_class and post_class
<?php
function add_post_title_class($classes) {
global $post;
if ($postTitle = sanitize_title($post->post_title)) {
$classes[] = $postTitle;
}
return $classes;
}
add_filter('body_class', 'add_post_title_class');
add_filter('post_class', 'add_post_title_class');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment