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

How to Hide WordPress Comment Module, Only Logged-in Users Can View

Due to domestic policy reasons, personal website filings do not allow websites to have comment functions. However, a personal blog without an open comment function 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; you just need to find the corresponding code and add a conditional statement.


	

`is_user_logged_in` checks whether the user is logged in. If logged in, the comment module will be displayed; if not, it won't 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:The code in this article is shared by Zhigengniao.

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

「Naibabiji WordPress Website Building Coaching」 — From selecting a domain and purchasing hosting to installing themes and publishing posts, I「ll guide you through every step, helping you avoid detours and reach your goals directly.

👉 Learn about 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 to Follow