• How to use wp_dequeue to keep a script from loading in WordPress: …or are there more options here we can use.

    background: The theme author is loading the Google Maps API but it isn’t being used on the site so I want to dequeue it in the child theme’s functions.php. They don’t offer an option to simply disable it within the theme settings.

    Would someone mind helping me out with some ideas about the options we have here:

    • a. we could comment it out in the parents theme or
    • b. dequeue it in the child theme? and what about the options to
    • c. deregister it

    so there are lots of options here: the wp_dequeue code

    questions:

    isnt it technically more efficient to comment it out in the parent theme or dequeue it in the child theme? I know the inherent problems with modifying the parent theme code.

    regarding the option … we could work with the

    <code class=””>

    <code class=””>(‘bazien-google-maps’, ‘https://maps.googleapis.com/maps/api/js?kewp_enqueue_script(‘bazien-google-maps&#8217;, ‘https://maps.googleapis.com/maps/api/js?ke

    but wait: isnt it the best WordPress way, we ‘ll need to deregister it in the child theme. to do so, use the following :

    <code class=””>

    <code class=””>wp_deregister_script( ‘bazien-google-maps’ );

    conclusio:; it’s more efficient to comment it in the parent theme, because this way we don’t load the script to “unload” it after. But, an update might appear somedays, so it’s more secure to disable it in the child theme.

    i am not sure if the above ideas and musings are correct. what do you say…

    See the cod WordPress for more informations aboubt registering scripts and styles:

    here and informations about deregistering: here

    Function Reference/wp deregister script: https://codex.ww.wp.xz.cn/Function_Reference/wp_deregister_script

    https://developer.ww.wp.xz.cn/reference/functions/wp_register_script/

    <code class=””>

    <code class=””>wp_register_script( string $handle, string|false $src, string[] $deps = array(), string|bool|null $ver = false, array|bool $args = array() ): bo etc. etx

    what do you say – which way to choose – which method!?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter munich123

    (@munich123)

    btw: if we choose the options 2

    b. dequeue it in the child theme


    Google_Map_API cally on my site are the following

    js?v=3&libraries=geometry%2Cplaces&language=en&ver=6.3.2
    common.js
    util.js

    thus the code in functions.php could be like so

    
    Thus the code that could work would be:
    
    function dequeue_google_maps_scripts() {
        wp_dequeue_script('common.js');
        wp_dequeue_script('util.js');
        wp_dequeue_script('js?v=3&libraries=geometry%2Cplaces&language=en&ver=6.3.2');
    }
    add_action('wp_enqueue_scripts', 'dequeue_google_maps_scripts', 100);
    

    what do you say bout this solution..!?

    btw: the text below was not formated well – it is the same as above – but not correct formated. so forget the texst below

    <code class=””>js?v=3&libraries=geometry%2Cplaces&language=en&ver=6.3.2

    <code class=””>common.js

    <code class=””>util.js …..

    subsequently we can use the following Codeblock for the functions.php sensu https://developer.ww.wp.xz.cn/themes/advanced-topics/child-themes/

    <code class=””> <code class=””>function dequeue_google_maps_scripts() {wp_dequeue_script(‘common.js’);

    <code class=””>wp_dequeue_script(‘util.js’);

    <code class=””>wp_dequeue_script(‘js?v=3&libraries=geometry%2Cplaces&language=en&ver=6.3.2’); }

    and

    add_action('wp_enqueue_scripts', 'dequeue_google_maps_scripts', 100); 

    what do you say!?

    • This reply was modified 2 years, 7 months ago by munich123.
    • This reply was modified 2 years, 7 months ago by munich123.

    Yes, you need to deregister and dequeue the Javascript in the child theme instead of making changes in the original theme to prevent these changes from getting vanished next time you update the theme.

    Thread Starter munich123

    (@munich123)

    first of all: many many thanks for your awesome support this is much much more than expected. : yes i think that deregister and dequeue the Javascript is a good idea. but i had no luck – at least not with my attempts.

    see this thread – where i seemed to get some awesome tipps.

    https://ww.wp.xz.cn/support/topic/i-am-having-a-heck-of-a-time-disabling-google-maps-from-my-wordpress-page/

    imagine : i was also working with patchcode from the Astoundifi-devs – which did not did the trick – solve the issues. now this approach seems to be going into a new direction:

    what seems to do the trick and is leading to a different result in the checks in mozilla developer-console is the

    Opaque Response Blocking (ORB) is a replacement for Cross-Origin Read Blocking (CORB – https://chromestatus.com/feature/5629709824032768).
    CORB and ORB are both heuristics that attempt to prevent cross-origin disclosure of “no-cors” subresources.

    note: i applied the code that was mentioned i(see the other thread) in the path that was described there.

    aterward i installed the plugin (necessary or not ..i installed the “complianz – GDPR / CCPA Cookie Consent-plugin: https://ww.wp.xz.cn/plugins/complianz-gdpr/ )

    see what i have got back in the mozilla-developer-console: https://pastebin.com/TfrDEuxw

    
    
    the ressource xyz wurde durch OpaqueResponseBlocking blockiert. Grund: "nosniff is true and mimeType is an opaque-blocklisted MIME type or its essence is 'text/plain'".
    
    Die Ressource unter "https://googleads.g.doubleclick.net/ xyz " wurde durch OpaqueResponseBlocking blockiert.
    Grund: "nosniff is true and mimeType is an opaque-blocklisted MIME type or its essence is 'text/plain'".
    
    Anfrage für Zugriff auf Cookies oder Speicher für "https://googleads.g.doubleclick.net/ xyz " wurde blockiert, weil sie von einem Element zur Aktivitätenverfolgung (Tracker) stammt und das Blockieren von Seitenelementen aktiviert ist.
    
    Die Ressource unter "https://pagead2.googlesyndication.com/pagead/gen_204?id=dv3-render&msg=fetch&cor=16509900279020177034&x=1&ct=76" wurde durch OpaqueResponseBlocking blockiert. Grund: "after sniff: nosniff is true".
    
    ie Ressource unter "https://pagead2.googlesyndication.com/pagead/gen_204?id=dv3-render&msg=running&ord=9279739716690&version=m202309260101" wurde durch OpaqueResponseBlocking blockiert. Grund: "after sniff: nosniff is true".
    
    Die Ressource unter "https://pagead2.googlesyndication.com/pagead/gen_204?id=dv3-render&msg=tlbr&ord=9279739716690&version=m202309260101&ct=76&x=1&cor=16509900279020177000" wurde durch OpaqueResponseBlocking blockiert. Grund: "after sniff: nosniff is true".
    
    
    translated: 
    
    The resource at "https://googleads.g.doubleclick.net/xyz" was blocked by OpaqueResponseBlocking.
    Reason: "nosniff is true and mimeType is an opaque-blocklisted MIME type or its essence is 'text/plain'".
    
    Request to access cookies or storage for "https://googleads.g.doubleclick.net/xyz" was blocked because it came from a tracker and page element blocking is enabled.
    
    The resource at "https://pagead2.googlesyndication.com/pagead/gen_204?id=dv3-render&msg=fetch&cor=16509900279020177034&x=1&ct=76" was blocked by OpaqueResponseBlocking. Reason: "after sniff: nosniff is true".
    
    The resource at "https://pagead2.googlesyndication.com/pagead/gen_204?id=dv3-render&msg=running&ord=9279739716690&version=m202309260101" was blocked by OpaqueResponseBlocking. Reason: "after sniff: nosniff is true".
    
    The resource at "https://pagead2.googlesyndication.com/pagead/gen_204?id=dv3-render&msg=tlbr&ord=9279739716690&version=m202309260101&ct=76&x=1&cor=16509900279020177000" was blocked by OpaqueResponseBlocking. Reason: "after sniff: nosniff is true".
    

    what do you say.. see the full result here
    https://pastebin.com/TfrDEuxw

    look forward to hear form you again. Regards munich

    Thread Starter munich123

    (@munich123)

    hi there – at the moment i am not sure if this above mentioned “results” are valid results. I am still persisting with this issue i will keep on searching

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

The topic ‘ways to stop scripts: here Google-Maps API: wp_dequeue or wp deregister script?’ is closed to new replies.