Created
October 23, 2016 01:27
-
-
Save vladimirlukyanov/e19f73c46fb20cad9c0e507690bbfe89 to your computer and use it in GitHub Desktop.
Shortcode style enqueue #3
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 | |
function your_prefix_detect_shortcode() { | |
global $wp_query; | |
$posts = $wp_query->posts; | |
$pattern = get_shortcode_regex(); | |
foreach ($posts as $post){ | |
if ( preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches ) | |
&& array_key_exists( 2, $matches ) | |
&& in_array( 'myshortcode', $matches[2] ) ) | |
{ | |
// css/js | |
break; | |
} | |
} | |
} | |
add_action( 'wp', 'your_prefix_detect_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment