I would like to hide a particular div from a specific user role on a page of my site, I tried to insert the following code in the function.php file of my theme, but unfortunately it doesn’t work, do you have any suggestions?
<?php
$user = wp_get_current_user();
if ( in_array( 'shop_manager', $user->roles ) ) {
?>
<script>
jQuery(document).ready(function( $ ){
jQuery( "#hide" ).empty();
});
</script>
<?php
}
?>
3
Answers
functions.php is for adding php functions to your site. If you wanted to print out HTML/JS in your theme, you would need to add this to your theme file (index.php or footer.php)
Place this code in your theme file and it should work.
Use the footer hook to inject your css/js code: