Aurangajeb

Run custom script-css based on user role through wp_head hook

Aug 20th, 2021 (edited)
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. /** Run custom inline CSS based on user id **/
  2. add_action( 'wp_head', 'run_my_custom_css');
  3. function run_my_custom_css() {
  4. global $current_user;
  5. $user_id = get_current_user_id();
  6. if( is_user_logged_in() && $user_id == '30'){
  7.     ?>
  8.     <style>
  9.         .read-more {display: none;}
  10.     </style>
  11.     <?php
  12.     }
  13. }
  14.  
  15.  
  16. /** Run custom inline JS based on user id **/
  17. add_action( 'wp_head', 'run_my_custom_javascript');
  18. function run_my_custom_javascript() {
  19. global $current_user;
  20. $user_id = get_current_user_id();
  21. if( is_user_logged_in() && $user_id == '1'){
  22.     ?>
  23.         <script>
  24.             alert('This alert will only show for the admin (user_id: 1)');
  25.         </script>
  26.     <?php
  27.    
  28.     }
  29.  
  30.  
  31. }
Add Comment
Please, Sign In to add comment