0

I have tried various snippets, like this:

<?php   
add_action( 'wp_print_scripts', 'load_captcha_script', 100 );
   function load_captcha_script() {
    if ( !is_page( '#register' ) ) {
        wp_deregister_script('google-recaptcha');
    }
   }

but it doesn't work in #register section with hash, I also tried with if (window.location.hash == "#register")

But nothing, recaptcha doesn't load when floating form appears, Is there a snippet that only loads the script when the section appears?

2
  • The # part stays on the browser and isn't submitted to the server, so you can't detect it in PHP, no. You'd have to change the way you're enqueueing the google-recaptcha script and write JavaScript that only loads it conditionally on the hash part, e.g. using jQuery.getScript(). But then if this is a single page app which will add #register without reloading the page from the server then you'll have to handle that case too. Presumably you already have client side script that handles #register?
    – Rup
    Oct 25 '20 at 13:29
  • @Rup The problem as you say is that it does not reload the page, and about client side script I don't have much idea, so I will have to try other antispam methods, thank you very much for your answer, it has clarified my doubts.
    – DrWho
    Oct 25 '20 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.