Hi,
I want only registered users to be able to read comments. Managed to do it with CSS but then the comments are still visible for non-users if the go to the source code of the page.
So the first answer here looks much better to me: https://stackoverflow.com/questions/22585442/wordpress-how-to-hide-comments-to-non-logged-users
So I added the code as described there in the comments.php file in the theme folder. And it works.. Kind of.
The comments are not visible for users that are not logged in.
However for logged in users a php code section is visible which does not look good.
Here is the part of the code that becomes visible for logged in users:
if ( ! defined( ‘ABSPATH’ ) ) { exit; // Exit if accessed directly. } /* * If the current post is protected by a password and * the visitor has not yet entered the password we will * return early without loading the comments. */ if ( post_password_required() ) { return; } /** * generate_before_comments hook. * * @since 0.1 */ do_action( ‘generate_before_comments’ ); ?>
So instead I pasted the code further down on the page but I still get this code showing above the comments sections for logged in users: do_action( ‘generate_before_comments’ ); ?>
And if I paste “<?php if (is_user_logged_in()): ?>” under that code as well – the page breaks.
Any advice on how to get this to work? I feel I’m very close but some extra advice would be good.
And btw: Do you have a place for donations? I feel you go above and beyond on your support here – and I very much like to keep it that way – so I’m happy to donate extra for my questions here.
Best regards
Lars