Skip to content

Instantly share code, notes, and snippets.

@zackkatz
Created May 24, 2018 00:32
Show Gist options
  • Save zackkatz/856b5997a00c71c9c88cbe4e0a25e7dd to your computer and use it in GitHub Desktop.
Save zackkatz/856b5997a00c71c9c88cbe4e0a25e7dd to your computer and use it in GitHub Desktop.
GravityView - Add body classes when View is being rendered
<?php
/**
* Add body class for GravityView contexts
*/
add_filter('body_class', function( $classes = array() ) {
if ( ! class_exists( '\GV\View_Collection' ) ) {
return $classes;
}
global $post;
// Edit Entry, Single Entry, or Multiple Entries for View CPT
if( $context = gravityview_get_context() ) {
$classes[] = 'gravityview-' . $context;
}
// Embedded Multiple Entries
else if ( $views = \GV\View_Collection::from_post( $post ) ) {
$classes[] = 'gravityview-directory';
}
return $classes;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment