There’s already a function for checking if a post has a shortcode: has_shortcode(): function enqueue_script_if_shortcode_is_detected() { global $post; wp_register_script( ‘leweb-widgets’, get_stylesheet_directory_uri() . ‘/includes/leweb-widgets.php’, ‘1.0’, true ); if ( has_shortcode( $post->post_content, ‘leweb_suggested_events’ ) ) { wp_enqueue_script(‘leweb-widgets’); } } add_action( ‘wp_enqueue_scripts’, ‘enqueue_script_if_shortcode_is_detected’ ); Just keep in mind that checking the post this way: Will not know if … Read more