1

How to add a javascript file or javascript code if the user is logged in to the website?

The website is built with drupal 7.

0

1 Answer 1

2

Try the following code:

global $user;
if($user->uid != 0)
{
    drupal_add_js("PATH_TO_JS_FILE");
}

Hope this helps... Muhammad.

Sign up to request clarification or add additional context in comments.

1 Comment

@OP: If you are wondering how to get this code working in your site, the easiest way (at least for me) is to create a tiny module that has hook_init. function mymodule_init(){ ABOVE CODE HERE }

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.