I am having a javascript code which i embed to the footer.php of my wordpress site to be shown on all the pages.

The javascript code is for a livechat support program.

My question is how do I make this livechat window available only to registered users or members?

PN: I am also using a third party plugin as a membership plugin.


  • What role/capability determines registered users or members? – Dave Romsey Nov 1 '16 at 0:16

WordPress provides the Conditional Tags. I think is_user_logged_in() tag will work for you. List of conditional tags available.

if ( is_user_logged_in()  ) 
  // include the JavaScript File

UPDATE: Also if you want to check the user roles etc.. you can use the current_user_can() you can check both the both roles and capabilities. Better to use the wp_get_current_user(); function like :

$current_user = wp_get_current_user();

$roles = array('editor', 'author');

if( array_intersect($roles, $current_user->roles ) && is_user_logged_in() ) {

   // include javascript file here etc...


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.