Home> CMS Tutorial> WordPress> body text

WordPress implements login visible comment module

藏色散人
Release: 2020-01-17 16:03:58
forward
2747 people have browsed it

The following columnWordPress Tutorialwill introduce to you how to implement the login visible comment module in WordPress. I hope it will be helpful to friends in need!

WordPress implements login visible comment module

Normally, WordPress can be set up to log in to post comments, but you can still see the content of comments normally without logging in. Recently, some users said that they have been notified that websites registered by individuals do not allow comments. Regarding the interactive function, although I have not received a notification, I can simply modify the template so that the topic comment module is only visible when logged in.

WordPressLog in visible comments module WordPress Log in visible comments module

Here we need to use WordPress’s function to determine whether to log in: is_user_logged_in()

Just wrap the comment module with a judgment function.

Take the WordPress default theme Twenty Seventeen as an example. Open the theme text template file single.php and find something similar:

if ( comments_open() || get_comments_number() ) : comments_template(); endif;
Copy after login

After changing it to:

if ( is_user_logged_in()){ if ( comments_open() || get_comments_number() ) : comments_template(); endif; }
Copy after login

, only the logged in Only in this state can you see the comment module and comment content.

Other theme methods are similar, such as:

    
Copy after login

The above is the detailed content of WordPress implements login visible comment module. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:zmingcx.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!