1

in the effort to fix an issue with my website, I needed to include a specific jQuery version through functions.php in my theme folder, but this leads to some compatibility problem with avada portfolios and other builder elements in some pages. How could I deregister a php script located in functions.php for 5 specific pages? If I delete the script, the portfolios and the other builder element come back to work.

I am sorry but I have a poor knowledge of php... This below is the code added to functions.php:

function add_jq_theme() { wp_enqueue_script( 'script-name', 
'https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js', array(), 
'1.0.0', true ); } add_action( 'wp_enqueue_scripts', 'add_jq_theme' );

Thank you a lot for your help, Tommaso

  • Have you tried wp_deregister_script('jquery'); and enqueue the right version? – Max Yudin May 8 at 11:24
  • Yes I tried that as well, but I don't know how to do it for a specific page – Tommaso Cerci May 8 at 11:34
  • This question is about adding script, but you can replace wp_register_script with wp_deregister_script. – nmr May 8 at 12:07
  • A lot of scripts like jQuery are cached by browser unless the coder states different. So, you can forget about loading speed or similar. Let it be, there is no speed question. Or you have a special case? – Max Yudin May 8 at 12:38
2

Haven't tested it but this should work with small tweaks:

function deregister_script_page_createit() {
    if( is_page( 42 ) ) {
        wp_deregister_script('jquery');
    }
}
add_action( 'wp_enqueue_scripts', 'deregister_script_page_createit' );
  • Thank you so much twelvell and all of you guys, this works properly! – Tommaso Cerci May 8 at 12:19
  • Yes, but what happens when page ID got to be changed when, for example, reanimating the site from the XML backup file? Hard-coded IDs are harmful. – Max Yudin May 8 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.