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' );
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.