Support

Account

Home Forums ACF PRO has_shortcode not detected? Reply To: has_shortcode not detected?

  • Hi John,

    Thank you for your answer.
    I change my function and it works well.

    For the records :

    
    <?php
    // CF7 Kill all
    add_filter( 'wpcf7_load_js', '__return_false' );
    add_filter( 'wpcf7_load_css', '__return_false' );
    // Load only if shortcode
    function vanois_load_cf7() {
        // if shortcode in acf fields flexible content
        if(have_rows('flexible_content')) {
            while (have_rows('flexible_content')) : 
                the_row();
                $raw_data = get_row();
                $cf7_shortcode = preg_grep("/contact-form-7/", $raw_data);
            endwhile;
            if ($cf7_shortcode) {
                wpcf7_enqueue_scripts(); 
            }
        // else if no flexible-content, check shortcode in wp default editor    
        } else {
            global $post;
            if( has_shortcode( $post->post_content, 'contact-form-7')) {
                wpcf7_enqueue_scripts(); 
            } 
        }
    }
    add_action( 'wp_enqueue_scripts', 'vanois_load_cf7' );
    ?>