Skip to content

Instantly share code, notes, and snippets.

@jesseeproductions
Created November 2, 2018 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesseeproductions/5f05637774bc704d52397a76fa6cb674 to your computer and use it in GitHub Desktop.
Save jesseeproductions/5f05637774bc704d52397a76fa6cb674 to your computer and use it in GitHub Desktop.
Load Loop Shortcode in Header if Found in Content
/**
* Load Loop Shortcode in Header if Found in Content
* https://wordpress.stackexchange.com/a/207749
*/
add_action( 'wp_enqueue_scripts', 'cctor_load_resources' );
function cctor_load_resources() {
global $post, $wpdb;
// determine whether this page contains "couponloop" shortcode
$shortcode_found = false;
if ( has_shortcode($post->post_content, 'couponloop') ) {
$shortcode_found = true;
} else if ( isset($post->ID) ) {
$result = $wpdb->get_var( $wpdb->prepare(
"SELECT count(*) FROM $wpdb->postmeta " .
"WHERE post_id = %d and meta_value LIKE '%%couponloop%%'", $post->ID ) );
$shortcode_found = ! empty( $result );
}
if ( $shortcode_found ) {
wp_enqueue_style( 'coupon_creator_css' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment