Created
November 2, 2018 12:44
-
-
Save jesseeproductions/5f05637774bc704d52397a76fa6cb674 to your computer and use it in GitHub Desktop.
Load Loop Shortcode in Header if Found in Content
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
/** | |
* 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