I am trying to update Jquery on my website (to Jquery 1.8.3) for the front end only.

I am using the following code below and it works fine. However, as I am using my theme for node/edit pages, the code breaks some of the contrib modules that are displayed on the node/edit pages.

How can I limit the code so it doesn't effect node/edit pages?

Here is the code I am using:

function mytheme_preprocess_page(&$variables) {
  // exclude backend pages to avoid core js not working anymore
  // you could also just use a backend theme to avoid this
    $scripts = drupal_add_js();
    $new_jquery = array(drupal_get_path('theme', 'mytheme') . '/scripts/jquery-1.8.3.js' => $scripts['core']['misc/jquery.js']);
    $scripts['core'] = array_merge($new_jquery, $scripts['core']);
    $variables['scripts'] = drupal_get_js('header', $scripts);


Steps I have tried:

1. Applying an if statement.

I have tried wrapping the code in the following if statement which comes from Method 4 on this page:

if (arg(0) != 'admin' || !(arg(1) == 'add' && arg(2) == 'edit') || arg(0) != 'panels' || arg(0) != 'ctools') {

However, this code seems to disable Jquery on all pages.

2. Using Jquery Update

This module brakes functionality on admin/contrib modules. It also seems to have permission errors.

3. Jquery Multi

I can't seem to get this module to work. (The module requires you to either move your Javascripts to the libraries folder (which isn't an option for me due to my workflow) or to add a number suffix to your scripts (which again isn't an option due to work flow).

Thanks for any help that can be offered.

  • Dev version of Jquery Update has this functionality – xurshid29 Dec 11 '13 at 10:54
  • @xurshid29 The dev version doesn't seem to work for anonymous users. – big_smile Dec 11 '13 at 10:54
  • So use my patch? – Mołot Dec 11 '13 at 10:55
  • @big_smile don't know how are you installing it, but in my project it works perfectly for both anonymous and authenticated users – xurshid29 Dec 11 '13 at 10:56
  • 1
    Your choice, but if you will start to redevelop that wheel again, you risk getting all the same problems. I'm using it for years without any significant issue I wasn't able to patch myself (the one I linked you to). Anyway, good luck on your chosen path of action. – Mołot Dec 11 '13 at 11:28

Your Answer

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

Browse other questions tagged or ask your own question.