The following column WordPress Tutorial will introduce to you how to implement the login visible comment module in WordPress. I hope it will be helpful to friends in need!
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.
WordPress Log 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;
After changing it to:
if ( is_user_logged_in()){ if ( comments_open() || get_comments_number() ) : comments_template(); endif; }
, only the logged in Only in this state can you see the comment module and comment content.
Other theme methods are similar, such as:
<?php if ( is_user_logged_in()){ ?> <?php if ( comments_open() || get_comments_number() ) : ?> <?php comments_template( '', true ); ?> <?php endif; ?> <?php } ?>
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!