Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosvarela/8bf5d69c740d27bdcbb187c5547479e0 to your computer and use it in GitHub Desktop.
Save carlosvarela/8bf5d69c740d27bdcbb187c5547479e0 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