🚀 Is building a website too difficult? Let me guide you step by step—Learn about the 「Naibabiji WordPress Website Building Coaching Service」 →

Method to Hide WordPress Comment Module, Only Visible to Logged-in Users

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.

🚀 Still feeling confused after reading the tutorial? Let me guide you step-by-step.

「Naibabiji WordPress Website Building Coaching Service」—From choosing a domain and buying hosting, to installing a Theme and publishing content, I「ll coach you through every step, helping you avoid detours and reach your goal directly.

👉 Learn about the Website Building Coaching Service
🔒

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.

×
二维码

Scan QR Code to Follow

AI Website Building Assistant

🤖
Hello! I am the Naibabiji AI Assistant. How can I help you?
Quick Consultation: