CF7 plugin assets (wordpress)

Selectively enqueue Contact Form 7 plugin assets.

<?php
/**
 * Selectively enqueue Contact Form 7 plugin assets.
 */
if (class_exists('WPCF7')) {
    add_action('wp_enqueue_scripts', function() {
        $load_scripts = false;
        if (is_singular()) {
            $post = get_post();
            if (has_shortcode($post->post_content, 'contact-form-7')) {
                $load_scripts = true;
            }
            if (!empty(get_post_meta($post->ID, 'contact_form', true))) {
                $load_scripts = true;
            }
        }
        if (!$load_scripts) {
            wp_dequeue_style('contact-form-7');
            wp_dequeue_script('contact-form-7');
            wp_dequeue_script('google-recaptcha');
        }
    });
}
?>

functions.php

< toolbox