PHP WordPress - Add Custom Field to Body Class

<?php add_filter( 'body_class', 'wpse_20160118__body_class' ); function wpse_20160118__body_class( $classes ) { if ( $package_color = get_field( 'package_color', get_queried_object_id() ) ) { $package_color = esc_attr( trim( $package_color ) ); $classes[] = $package_color; } return $classes; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.