Skip to content

Instantly share code, notes, and snippets.

@mathetos
Created November 3, 2016 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathetos/532b45c10ebf3dd24bd86b2756ed90cd to your computer and use it in GitHub Desktop.
Save mathetos/532b45c10ebf3dd24bd86b2756ed90cd to your computer and use it in GitHub Desktop.
Dequeue Maps Builder JS except certain pages
<?php
/**
* Dequeue GMB script for certain pages
*
* Hooked to the wp_print_scripts action, with a late priority (100),
* so that it is after the script was enqueued.
*/
function gmb_dequeue_script() {
global $post;
wp_deregister_script( 'google-maps-builder-gmaps' );
wp_dequeue_script( 'google-maps-builder-gmaps' );
$posts = array(754, 586);
if ( in_array($form_id, $posts) ) {
wp_register_script( 'google-maps-builder-gmaps' );
wp_enqueue_script( 'google-maps-builder-gmaps' );
}
}
add_action( 'wp_print_scripts', 'gmb_dequeue_script', 100 );
@brycejacobson
Copy link

Tried using this but "$form_id" isn't referenced anywhere and throws an error. It then also didn't like the way the "wp_register_script() was being used saying missing 2nd argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment