Add CSS Page Name Classes to Your WordPress Body Tag

Super handy WordPress filter that adds your page names as a CSS class to the WordPress body_class function. Add the following to functions.php….filter-licious.

function page_class($classes) {
   global $wp_query;
   $page = '';
   $page = $wp_query->query_vars['pagename'];
   // add 'pagename' to the $classes array
   $classes[] = $page;
   // return the $classes array
   return $classes;

Leave a Reply

Your email address will not be published. Required fields are marked *