Last active
February 8, 2018 14:45
-
-
Save aaronsummers/50b4f8f7c746a32a040ed39f80cdb5e5 to your computer and use it in GitHub Desktop.
Check metabox to add a body class, then include scripts if condition is met.
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
/* IN YOUR TEMPLATE FILE ABOVE THE HEADER CALL */ | |
add_action( 'body_class', 'add_my_bodyclass'); | |
function add_my_bodyclass( $classes ) { | |
global $post; | |
$condition = get_post_meta( $post->ID, 'METABOX_ID', true ); | |
// Some condition to compare / check | |
if ( ! EMPTY( $conditon ) ) : | |
$classes[] = 'CUSTOM_CLASS'; | |
endif; | |
$classes[] = ''; | |
return $classes; | |
} | |
/* THEN IN THE ENQUE FUNCTION */ | |
$classes = get_body_class(); // Check body classes must be included | |
if ( in_array('CUSTOM_CLASS', $classes) ) : | |
wp_enqueue_script( 'video', get_template_directory_uri() . '/assets/js/jquery.background-video.js', array( 'jquery' ), '1.0.0', true ); | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment