1

How can I not execute some <script> </script> if the user is an administrator or any specific role?

Basically I need to do something like this:

 <?php if( !User( 'Administrator', 'Editor' ) ) { <script> </script> } ?> 
3
  • This post will help you wordpress.stackexchange.com/questions/60272/… AND wordpress.stackexchange.com/questions/131814/… Commented Jul 6, 2016 at 5:43
  • And one more thing! You can't use <script> tag inside <?php ?> (php tag)!! Before using <script> you need to close php tag first like this ?> <script> </script> <?php. Commented Jul 6, 2016 at 5:48
  • @Rishabh The two post isn't working for my needs. I need to execute the script if the User is not "LogIn" and if the User is not an administrator. Could you give me a sample code? Commented Jul 6, 2016 at 6:03

1 Answer 1

0

Solution, using and statement '&&' for another specific role.

Closing <?php if() : ?>, <?php else : ?> Tag with a Column : to be able to post scripts inside the Loop.

<?php global $current_user; // Use global get_currentuserinfo(); // Make sure global is set, if not set it. if ( ! user_can( $current_user, "administrator") && ! user_can( $current_user, "specific_role" ) ) : ?> // Check user object has not got subscriber role <!-- Not Administrator --> <?php else : ?> <!-- Administrator --> <?php endif; ?> 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.