Due to domestic policy reasons, personal website filings do not allow websites to have comment functionality. However, a personal blog without open comments seems to lack soul. Therefore, we can set it so that only logged-in users can see the comment area content. The specific method is as follows: Find your theme's single.php file, for example, in the Twenty Seventeen theme, locate code similar to the following.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
Modify it as shown below:
if ( is_user_logged_in()){
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
}The method for other themes is similar; just find the corresponding code and add a conditional check.
<?php if ( is_user_logged_in()){ ?>
<?php if ( comments_open() || get_comments_number() ) : ?>
<?php comments_template( '', true ); ?>
<?php endif; ?>
<?php } ?>`if ( is_user_logged_in() )` is the condition to check if the user is logged in. If logged in, the comment module is displayed; if not, it won't load. Of course, after making this change, you need to enable user registration on your website. You might also be interested in the following articles:
The code in this article was shared by Zhigengniao.
Comments are closed
The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.