How to restrict the user from viewing comments but with option to write comments?

How to restrict the user from viewing comments. the regular user can only write comments but only the administrator can see all the comments?

if is there any plugin or other solution I'll be grateful.

Thanks

Solutions

You shouldn't ask for plugins recommendations here since that is considered offtopic.

That being said, what you can do is to modify the comments.php file of your theme, I recommend you to use a childtheme, in that file you will locate where the comments are being shown and you will enclose it on:

<?php if( current_user_can('editor') || current_user_can('administrator') ) {  ?> 
    // comments, only admins or editors can read
<?php } ?>

Similar questions

Conditional based on the User Role of the Current Profile the user is viewing - BuddyPress
I'm using BuddyPress and need a certain block of code to show up on user role Store Owner profiles only. I'll be putting it in member_header.php, so it's just a template file. I've been digging for a long time now and just can't seem to figure this out. I found a way to target current user role, but that makes it show up on everyone's profile for a...
Viewing all user metadata in user-edit.php or how to override
I have added some metadata into the account page of my users. I want this data to be shown and editable in the user-edit.php page which shows user information. I thought of modifying this file, but I later realized that if there is a WordPress update, this file would be overwritten. How should I do this?
Is the viewing (author.php) page user the matching user?
I'm currently playing around with Wordpress user's profile pages author.php and would like to implement a personal information front-end edit ability for users AND public statistical user data fallback for any other user viewing the page. I'm looking for a secure way to determine if the user currently viewing the author.php user page, is the matchi...
restrict write access to folder using .htaccess and ip address
We would like to restrict 'write' access to a directory just to users accessing the site from our network static ip address. This example works to restrict access to a folder from an ip, Obviously however folders like wp-content needs to be accessed from all ip addresses. We just want to stop it being edited unless the user is on our network. We do...
Allow contributors to moderate comments comments on posts they write
I run a multi-author wordpress site where we have a large number of contributors that can write articles, which are published after they are reviewed by an editor. (This is all standard wordpress behaviour). What I would like to do is give the contributors the ability to moderate comments on the posts which they write, but not on posts written by o...
Allow viewing the edit screen for a post type, but not make/save/publish/update changes
I have been searching the documentation on how to do this. There is a user type manager who should be able to see the edit page of a custom post type called employees. The manager should be able to see the custom post fields but not edit them. The custom post type employee does not have it's own view. As in, an employee does not have it's own page....

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.