Hide comment feature if not logged in
-
WordPress Dashboard –> Settings –> Discussion Settings –> Other comment settings and check Users must be registered and logged in to comment .
Moved to support since the feature is already there in WordPress core.
Add this to child-theme
functions.php
and let me know if it works,<?php
/**
* Helps to determine if the comments should be shown.
* This function has been edited to hide comments if the user is not logged in.
*/
function graphene_should_show_comments() {
global $graphene_settings, $post;
if ( ! isset( $post ) ) return;
if ( $graphene_settings['comments_setting'] == 'disabled_completely' )
return false;
if ( $graphene_settings['comments_setting'] == 'disabled_pages' && get_post_type( $post->ID ) == 'page' )
return false;
if ( ! is_singular() && $graphene_settings['hide_post_commentcount'] )
return false;
if ( ! comments_open() && ! is_singular() && get_comments_number( $post->ID ) == 0 )
return false;
if ( !is_user_logged_in() )
return false;
return true;
}No, no. Don’t copy the entire functions.php file to child theme. Create a blank functions.php and add the above code.
You can download the child theme template from my site. Link is in my signature.
Viewing 10 posts - 1 through 10 (of 10 total)
- You must be logged in to reply to this topic.