Hello,
We are attempting to conditionally load certain libraries (CF7’s in this context) only when specific shortcodes are being used. We are detecting the codes properly when looking at the post’s content, but not when Pro headers (or footers) contain it (like putting a contact form inside a popup hidden in the footer).
How can we access the current header’s content? (so we can look for the shortcode in it)
See code below.
function wpcf7o_dequeue_scripts() {
$load_scripts = false;
if ( is_singular() ) {
$post = get_post();
if( has_shortcode( $post->post_content, 'contact-form-7' ) ) {
$load_scripts = true;
}
}
if ( ! $load_scripts ) {
wp_dequeue_script( 'contact-form-7' );
wp_dequeue_style( 'contact-form-7' );
} else {
add_action( 'wp_head', 'wpcf7o_track_mailsent' );
}
}
if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
add_action( 'wp_enqueue_scripts', 'wpcf7o_dequeue_scripts', 99 );
}
Any hint or help would be appreciated! 

