Google reCaptcha and Category Pages

#103744
  • Resolved Georgi
    Rank Math free

    Hello,

    Wonderful plugin you’ve got there.
    I’ve removed the category base for my WooComemerce starter site.

    I’m using the Contact Form 7 plugin + Google reCaptcha.

    With the help of this code, Google reCaptcha is stopped from running on every page except the contact page.

    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' );
    	}
    });

    However, reCaptcha still runs on all product catagory pages and I think it’s connected with the fact that the category base is removed.

    Any idea how to go around this and also stop reCaptcha runnning on product category pages?

    Regards!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello,

    You can add an option to check if the page is a WooCommerce product category page:

    
    if(is_product_category())
    {
    	wp_dequeue_script( 'google-recaptcha' );
    	wp_dequeue_script( 'wpcf7-recaptcha' );
    }
    

    Hope this helps you. Thank you.

    ​​​​​​

    Hello Davis,

    Thank you very much for helping.

    I’ll admit I’m not handy with coding, should the code be added directly after the first check?

    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' );
    	}
    
    if(is_product_category())
    {
    	wp_dequeue_script( 'google-recaptcha' );
    	wp_dequeue_script( 'wpcf7-recaptcha' );
    }
    });

    Hello,

    The following might help:

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

    Hope this helps you. Thank you.

    ​​​​​​

    Thank you very much, Michael! It worked 🙂

    Thread resolved.

    Hello,

    We glad to be of help and happy that the issue is resolved.

    If you need further help or with anything else, please open a new support ticket here so we can help

    We are always here for assistance.

Viewing 6 replies - 1 through 6 (of 6 total)

The ticket ‘Google reCaptcha and Category Pages’ is closed to new replies.