Skip to content

Instantly share code, notes, and snippets.

@Daniel-Walsh
Last active October 1, 2021 02:28
Show Gist options
  • Save Daniel-Walsh/5d7740ebab4cf44f7abe0f16ed4212fb to your computer and use it in GitHub Desktop.
Save Daniel-Walsh/5d7740ebab4cf44f7abe0f16ed4212fb to your computer and use it in GitHub Desktop.
Adds the current page template filename to the body classes #wordpress #php
<?php
/**
* Function : add_page_template_body_class
* Description : Adds the current page template filename to the body classes.
* Author : Dan Walsh
*
* @param array $classes : The array of classes attached to the body element.
*/
function add_page_template_body_class( $classes ) {
global $post;
$classes[] = basename( get_page_template( $post->id ), '.php' );
return $classes;
}
add_filter( 'body_class', 'add_page_template_body_class' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment