<?php add_filter( 'body_class', 'custom_body_class' ); /** * Add custom field body class(es) to the body classes. * * It accepts values from a per-page custom field, and only outputs when viewing a singular static Page. * * @param array $classes Existing body classes. * @return array Amended body classes. */ function custom_body_class( array $classes ) { $new_class = is_page() ? get_post_meta( get_the_ID(), 'body_class', true ) : null; if ( $new_class ) { $classes[] = $new_class; } return $classes; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter