• Resolved Masahiko Kawai

    (@masakawai)


    Hello.

    After updating to 5.4, wpcf7_enqueue_scripts stopped working.

    For testing, I put the following code in functions.php, referring to “Loading JavaScript and stylesheet only when it is necessary” on the official website.

    add_filter( 'wpcf7_load_js', '__return_false' );
    add_filter( 'wpcf7_load_css', '__return_false' );
    
    if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
        wpcf7_enqueue_scripts();
    }
    
    if ( function_exists( 'wpcf7_enqueue_styles' ) ) {
        wpcf7_enqueue_styles();
    }

    Then, JS and CSS are loaded in 5.3.2, but not in 5.4 or later.

    Best regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • hi @masakawai

    you need to enqueue the function in this way:

    add_filter( 'wpcf7_load_js', '__return_false' );
    add_filter( 'wpcf7_load_css', '__return_false' );
    
    function cf7_script_and_style() {
       // add here the logic to return if this isn't the contact page
       if ( function_exists( 'wpcf7_enqueue_scripts' ) ) wpcf7_enqueue_scripts();
       if ( function_exists( 'wpcf7_enqueue_styles' ) ) wpcf7_enqueue_styles();
    }
    add_action( 'wp_enqueue_scripts', 'cf7_script_and_style' ); //or wp_footer or wp_body_open etc
    • This reply was modified 3 years, 3 months ago by Erik.
    • This reply was modified 3 years, 3 months ago by Erik.
    Thread Starter Masahiko Kawai

    (@masakawai)

    Hi Erik.

    By using the action hook to enqueue, JS and CSS are now loaded even after 5.4.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wpcf7_enqueue_scripts not Working 5.4’ is closed to new replies.