Skip to content

Instantly share code, notes, and snippets.

@rupokify
Created February 1, 2021 05:19
Show Gist options
  • Save rupokify/8d491055c20f3a0af91fb69bd6439a38 to your computer and use it in GitHub Desktop.
Save rupokify/8d491055c20f3a0af91fb69bd6439a38 to your computer and use it in GitHub Desktop.
Deregister Stock jQuery and Load Custom jQuery on Specific Pages/Posts
<?php
// WordPress 5.6 comes with a very recent version of jQuery and it's not suggested to use an older one.
if (!function_exists('load_custom_jquery')) {
function load_custom_jquery() {
if (is_page(array('page-slug-one', 'page-slug-two'))) { // Replace 'page-slug-one', 'page-slug-two' etc with your own page slug
wp_dequeue_script('jquery');
wp_deregister_script('jquery');
wp_register_script('custom-jquery', 'YOUR_CUSTOM_JQUERY_URL_OR_PATH_HERE', false, 'X.X.X', 'true'); // Replace 'YOUR_CUSTOM_JQUERY_URL_OR_PATH_HERE' with actual path and 'X.X.X' with the version of that jQuery
wp_enqueue_script('custom-jquery');
}
}
}
add_action('wp_enqueue_scripts', 'load_custom_jquery');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment