Support » Plugin: Contact Form 7 » Form not send

  • daya143

    (@daya143)


    hello,
    i want contact form only load on some pages so i add this code

    // Stop loading Contact From 7 CSS and Javascript on all pages.
        if( is_singular () ) {
            $post = get_post ();
            if( has_shortcode( $post -> post_content, 'contact-form-7' ) ) {
                $check_cf7 = true;
            }
        }
        if( !$check_cf7 ) {
            wp_dequeue_script( 'contact-form-7' );
            wp_dequeue_style ( 'contact-form-7' );
        }
    function wps_contact_form_7_check_dequeue() {
        //Set to false to be able to check against something
        $check_cf7 = false;
        // Page ID, title, slug, or array of such.
        // if ( is_page( array( 37, 'contact-us', 'Contact US' ) ) ) {
        // if ( is_page( 'contact-us' ) ) {
        if ( is_page( array( 213, 'PAGE1', 'PAGE2' ) ) ) {
                $check_cf7 = true;
        }
        //so therefore dequeue only if is false 
        if ( !$check_cf7 ) {
            wp_dequeue_script ( 'contact-form-7' );
            wp_dequeue_style ( 'contact-form-7' );
        }
    }
    add_action( 'wp_enqueue_scripts', 'wps_contact_form_7_check_dequeue', 77 );

    i need the recaptcha also load only on the pages CF7 is usd, so i try this code

    // recaptcha
    add_action('wp_print_scripts', function () {
        global $post;
        if ( is_a( $post, 'WP_Post' ) && !has_shortcode( $post->post_content, 'contact-form-7') ) {
            wp_dequeue_script( 'google-recaptcha' );
            wp_dequeue_script( 'wpcf7-recaptcha' );
        }
    });

    After adding this the CF7 is not working, gettting error.
    How i can solve this please

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Form not send’ is closed to new replies.