Created
May 24, 2018 00:32
-
-
Save zackkatz/856b5997a00c71c9c88cbe4e0a25e7dd to your computer and use it in GitHub Desktop.
GravityView - Add body classes when View is being rendered
This file contains hidden or 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
<?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