2

I am using the following to put js on my site...

drupal_add_js(drupal_get_path('theme', 'MYTHEME') . '/js/custom.js');

But I have noticed that this is also adding the js to pages like update.php and other admin pages. Is there a if variable I can use to only load the js on customer facing pages?

Ive used drupal_is_front_page() before, which is great, is there a drupal_not_admin_page() or something like that?

A google search for "drupal is not admin page" isnt getting me anywhere.

2 Answers 2

3

You can use path_is_admin():

if (!path_is_admin(current_path())) {
  // Do something...
}

Or check the theme:

if ($GLOBALS['theme'] == 'some_theme') {
  // Do something...
}
0
0

Try below code :

function mytheme_preprocess_page(&$vars) {
  // clean script from the admin pages
  if (arg(0) != 'admin' || !(arg(1) == 'add' && arg(2) == 'edit') || arg(0) != 'panels' || arg(0) != 'ctools') {
    drupal_add_js(drupal_get_path('theme', 'MYTHEME') . '/js/custom.js');
  }
}
2
  • 1
    This isn't reliable - you can designate pages to use or not use the admin theme through hook_admin_paths(), so you need to check the API (or current theme), not the URL
    – Clive
    Jun 8, 2015 at 13:16
  • Ok then pls have a look. Click Here.
    – Nishant
    Jun 8, 2015 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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