• Resolved bward

    (@bward)


    I appreciate the plugin, but I only need it to run on one page. However, I see the styles/scripts run on all pages. I typically dequeue styles/scripts by using the following function, but it’s not working to dequeue this plugin.

    Can you please advise how to accomplish that please? Thanks so much.

    function cf_turnstile_dequeue_scripts() {
        if( ! is_page( '123456' ) ) {
    
                wp_deregister_script( 'cfturnstile' );
                wp_dequeue_script( 'cfturnstile' );
    
                wp_deregister_style( 'cfturnstile-css' );
                wp_dequeue_style( 'cfturnstile-css' );
            }
    }
    
    add_action( 'wp_print_scripts', 'cf_turnstile_dequeue_scripts', 100 );
    add_action( 'wp_print_styles', 'cf_turnstile_dequeue_scripts', 100 );
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Elliot Sowersby

    (@elliotvs)

    Hi,

    Thanks for the message.

    The way it is coded already, the required scripts should only be being loaded on the pages that have Turnstile widget on them. Any pages that don’t have Turnstile on, shouldn’t be loading the scripts.

    Could you check this on your end to see if that’s the case?

    Thanks!

    Thread Starter bward

    (@bward)

    I can confirm,

    Are loading on every page. I do use Elementor and have a subscription form popup if someone clicks a link. So that’s why this is occurring. I confirmed that, by turning off the Elementor popup.

    If there a way I can manually dequeue? I only need this for the contact page. Thanks!

    Plugin Author Elliot Sowersby

    (@elliotvs)

    Yes if the subscription form popup is loaded on every page, and you have Turnstile on this form, then it will load the scripts on all pages.

    You could try using this:

    remove_action("cfturnstile_enqueue_scripts", "cfturnstile_script_enqueue");
    Thread Starter bward

    (@bward)

    Thanks for the followup, you helped save the day.

    I made the magic happen with this for anyone else who may need it.

    function cf_turnstile_dequeue_scripts() {
        if( ! is_page( '123456' ) ) {
    
    remove_action('cfturnstile_enqueue_scripts', 'cfturnstile_script_enqueue');
    
            }
    }
    add_action( 'wp_print_scripts', 'cf_turnstile_dequeue_scripts', 100 );
    Thread Starter bward

    (@bward)

    I just realized this causes another issue.

    Within the plugin, we have the setting “Enable on all Elementor Forms” on. With the dequeue script, it removes this plugins scripts/styles from all pages except one as we wanted, but this causes an issue.

    Our subscribe (on all pages) form is still expecting to authenticate via the plugin setting, being “Enable on all Elementor Forms”. So we haven’t had any subscribes in a week. I just tested this out this morning.

    So then, we really need a way to only “Enable on all Elementor Forms” on one page.

    Is that possible?

    Plugin Author Elliot Sowersby

    (@elliotvs)

    Thanks for the info.

    Sadly, currently with the Elementor integration, it is only possible to enable Turnstile for all Elementor forms on your site. You can not currently choose which individual forms it shows on.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to dequeue styles and scripts for this plugin?’ is closed to new replies.