Hide comment feature if not logged in

  • heinohund


    Hi There,

    I wish for a feature there can hide the ability to read or write comments on a post if user i not logged in.

    Best regards




    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.



    But what i want is to hide the comment if not logged in.

    The standard WP only hide the write option not the read option



    Add this to child-theme functions.php and let me know if it works,

    * 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;



    Do i just make a copy of the functions.php and place it in the childfolder?

    Or do i past into blank finctions.php and place it in chilfolder?



    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.



    I allready have a childtema 🙂

    I try make a new freesh functions.php



    I think it’s working 🙂

    You are a genius!!

    I’ll put in my main site tomorrow!!






    And working in prduction as well 🙂

    Thanks again!



Viewing 10 posts - 1 through 10 (of 10 total)

  • You must be logged in to reply to this topic.
Do NOT follow this link or you will be banned from the site!