Skip to content

Instantly share code, notes, and snippets.

@mattradford
Last active September 18, 2020 20:30
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mattradford/e3c4ccb5712d117cb7e9 to your computer and use it in GitHub Desktop.
Save mattradford/e3c4ccb5712d117cb7e9 to your computer and use it in GitHub Desktop.
Echo ACF custom field in body class
// ACF field added to body class
// Adapted from http://krogsgard.com/2012/wordpress-body-class-post-meta/
add_filter('body_class','tend_custom_field_body_class');
function tend_custom_field_body_class( $classes ) {
global $wp_query;
$postid = $wp_query->post->ID;
if ( is_page_template('template-service-index.php') ) {
$classes[] = 'variant-'.get_field('colour_scheme', $postid);
}
// return the $classes array
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment