How to check if short code is present in template?
Question
in that plugin i declared a short code but i want to enqueue the scripts only on those pages which have the short code. I tried This code =>
global $post;
if ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'MyShortCode') ) {
wp_enqueue_style('style_ui');
wp_enqueue_script('script_ui');
}
it is working fine until i am adding the short code inside a template directly
echo do_shortcode( '[MyShortCode]' );
I also enqueued scripts inside short-code function
public function shortcodeui($atts) {
wp_enqueue_style('style_ui');
wp_enqueue_script('script_ui');
require_once MYPL_PATH. 'templates/public/public.php';
}
but its not working for template please help
0
1 month
0 Answers
8 views
0
Leave an answer
You must login or register to add a new answer .