I changed from tags to ‘has_shortcode’
I was actually just working on that as your update came in. I am using this following code now for WP-Polls and Contact form 7. (Found and modified the code, BTW.)
I just figured out it would do what you mentioned as I have some polls in custom fields. Fortunately, with my theme on those polls, I can put the shortcode in the editor which doesn’t actually display. I have a CMS style theme that pulls everything from custom fields. I don’t have any polls in sidebars, so I am OK there. I think this will work for me, but it probably would not work for everyone. Now I just have to go do a search for my custom field shortcodes in phpMyAdmin and I should be set.
Thanks for the feedback.
// DEREGISTER PLUGIN EVENTS
function dvk_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' );
}
$load_poll_scripts = false;
if( is_singular() ) {
$post = get_post();
if( has_shortcode($post->post_content, 'poll') ) {
$load_poll_scripts = true;
}
}
if( ! $load_poll_scripts ) {
wp_dequeue_script( 'wp-polls' );
wp_dequeue_style( 'wp-polls' );
}
}
add_action( 'wp_enqueue_scripts', 'dvk_dequeue_scripts', 99 );