
Due to domestic policy, personal filing does not allow websites to have comment functionality, but a personal blog without comment functionality seems soulless, so we can set it so that only logged-in users see the comment area content. The specific method is as follows:
Find the single.php file of your theme, for example, the Twenty Seventeen theme, find 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 determines whether the user is logged in. If logged in, the comment module is displayed; if not logged in, it will not load.
Of course, after making this modification, you need to enable user registration on your website. You might also be interested in the following articles:
- Three WordPress Invitation Code Plugins_Website Invitation Registration Link Generation
- WordPress Membership Center Plugin Ultimate Member Usage Tutorial
- Several Methods for Users to Set Their Own Password During WordPress Website Registration
- Method to make a WordPress website accessible only to registered and logged-in members
The code in this article was shared by Zhigengniao.