Skip to content

Instantly share code, notes, and snippets.

@samkent
Last active June 28, 2018 19:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save samkent/7a3bfe1ea207652a98dc to your computer and use it in GitHub Desktop.
Save samkent/7a3bfe1ea207652a98dc to your computer and use it in GitHub Desktop.
WordPress add body class if page template
<?php
/**
* Add a custom body class for a specific page template
* Add the following to your theme functions.php file.
*/
add_filter( 'body_class', 'custom_class' );
function custom_class( $classes ) {
if ( is_page_template( 'templates/page-contact.php' ) ) {
$classes[] = 'contact';
}
return $classes;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment