Last active
September 18, 2020 20:30
-
-
Save mattradford/e3c4ccb5712d117cb7e9 to your computer and use it in GitHub Desktop.
Echo ACF custom field in body class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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