[Support request] Remove comments with php

Home Forums Support Remove comments with php

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #972808


    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

    Customer Support

    Hi there,

    i would try:

    1. Create a copy of the comments.php template and add that to your child theme.
    2. Edit the child theme template and just below this:

    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly.


    if (!is_user_logged_in()) {

    Donations are always welcome and its very kind of you – you can find the form here:


Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.