{"id":954,"date":"2025-03-24T14:28:07","date_gmt":"2025-03-24T14:28:07","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/how-to-prevent-gd-javascript-from-loading-on-non-gd-pages\/"},"modified":"2026-02-09T06:58:43","modified_gmt":"2026-02-09T06:58:43","slug":"how-to-prevent-gd-javascript-from-loading-on-non-gd-pages","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/code-snippets\/how-to-prevent-gd-javascript-from-loading-on-non-gd-pages\/","title":{"rendered":"How to Prevent GD JavaScript from Loading on non-GD Pages?"},"content":{"rendered":"\n<div class=\"wp-block-blockstrap-blockstrap-widget-alert d-flex align-items-center fade show alert alert-danger mb-3\" role=\"alert\"><span class=\"fas fa-exclamation-triangle me-2\"><\/span><span class=\"flex-grow-1\">By default, GeoDirectory will now try only to load our scripts on pages that require it. In most cases the below code will no longer be needed.\n<br>Please apply this snippet only to pages without GeoDirectory widgets, as using it elsewhere may cause compatibility issues.<\/span><\/div>\n\n\n\n<p>At times, you might not need GeoDirectory JavaScript to load on certain pages of your site. For example, you may have blog posts or sections of your site with custom styles and JS. In such cases, it is preferable to prevent GeoDirectory JavaScript from loading on such pages.&nbsp;<\/p>\n\n\n\n<p>You can use the following <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/useful-plugins\/code-snippets-plugin\/\">Code Snippet<\/a> to accomplish this:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">\/**\n * Dequeue core scripts &amp; styles on non GD pages.\n *\n * Note: This may cause JavaScript errors when page contains widget\/shortcode from GD.\n *\/\nfunction gd_snippet_dequeue_scripts() {\n    if ( class_exists( &#039;GeoDir_Frontend_Scripts&#039; ) &amp;&amp; ! geodir_is_geodir_page() &amp;&amp; !is_page(&#039;my-custom-page&#039;) ) {\n        global $geodir_location_manager;\n\n\n        \/\/ GeoDirectory\n        remove_action( &#039;wp_enqueue_scripts&#039;, array( &#039;GeoDir_Frontend_Scripts&#039;, &#039;load_scripts&#039; ) );\n        remove_action( &#039;wp_print_scripts&#039;, array( &#039;GeoDir_Frontend_Scripts&#039;, &#039;localize_printed_scripts&#039; ), 5 );\n        remove_action( &#039;wp_print_footer_scripts&#039;, array( &#039;GeoDir_Frontend_Scripts&#039;, &#039;localize_printed_scripts&#039; ), 5 );\n\n        \/\/ Location Manager\n        if ( ! empty( $geodir_location_manager ) ) {\n            remove_action( &#039;wp_enqueue_scripts&#039;, array( $geodir_location_manager, &#039;add_styles&#039; ), 10 );\n            remove_action( &#039;wp_enqueue_scripts&#039;, array( $geodir_location_manager, &#039;add_scripts&#039; ), 10 );\n        }\n\n        if ( class_exists( &#039;GeoDir_Frontend_Scripts&#039; ) &amp;&amp; ! geodir_is_geodir_page() &amp;&amp; !is_front_page() ) {\n            remove_action(&#039;wp_footer&#039;, array( &#039;GeoDir_Frontend_Scripts&#039;, &#039;js_location_functions&#039; ));\n            remove_action( &#039;wp_enqueue_scripts&#039;, array( &#039;GeoDir_Frontend_Scripts&#039;, &#039;load_scripts&#039; ) );\n            remove_action( &#039;wp_print_scripts&#039;, array( &#039;GeoDir_Frontend_Scripts&#039;, &#039;localize_printed_scripts&#039; ), 5 );\n            remove_action( &#039;wp_print_footer_scripts&#039;, array( &#039;GeoDir_Frontend_Scripts&#039;, &#039;localize_printed_scripts&#039; ), 5 );\n            remove_action(&#039;wp_footer&#039;,&#039;geodir_location_autocomplete_script&#039;);\n        }\n    }\n}\n\nadd_action( &#039;wp&#039;, &#039;gd_snippet_dequeue_scripts&#039;, 100 );<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>At times, you might not need GeoDirectory JavaScript to load on certain pages of your site. For example, you may have blog posts or sections of your site with custom styles and JS. In such cases, it is preferable to prevent GeoDirectory JavaScript from loading on such pages.&nbsp; You can use the following Code Snippet [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[819,817,818],"article\/categories":[211,433],"class_list":["post-954","gd_place","type-gd_place","status-publish","hentry","gd_place_tags-disable-javascript","gd_place_tags-defer-javascript","gd_place_tags-block-javascript","gd_placecategory-tips-tricks-more","gd_placecategory-code-snippets"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/954","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/types\/gd_place"}],"author":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/comments?post=954"}],"version-history":[{"count":3,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/954\/revisions"}],"predecessor-version":[{"id":2174,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/954\/revisions\/2174"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=954"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=954"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}