Tagged: 

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #347857

    Hi,

    I’m trying to find a php-only solution, for use in a functions file, that disables only the comment form itself. All I can find is code which disables everything comment related. But I’d like to keep the comments and comment counts… just the form itself has to disabled in certain cases.

    I want to display the comment form only when a certain parameter is in the post URL.

    The only thing I can think of is to use comment_form() and use it to give the form another ID (when it needs to be hidden). And then use display: none on that ID. But that would involve some CSS.

    Does anyone know of a php-only solution?

    Thanks in advance.

    Kind regards,

    Ralph

    #347969

    Hey Ralph12!

    The code your looking for is on line 164 in the /enfold/comments.php template.

    comment_form();
    

    You can surround it with an if statement and do some kind of check there.

    Regards,
    Elliott

    • This reply was modified 9 years, 11 months ago by Elliott.
    #348103

    Hey Elliott!

    Thank you for your suggestion! The only problem with modding comments.php, is that it wouldn’t be update-proof. But it seems to be the only way to specifically target the comment form itself.

    I do have 2 solutions that can be made update-proof, by placing them in a custom functions file. But they seem to remove comment counts as well. But I’m going to share ’em anyway, as they might be of some use to someone else.

    Solution 1
    Can be used to close comments for certain posts:

    function close_comment_form( $open, $post_id ) {
        $post = get_post( $post_id );
        if( $post->post_type == 'post' ) {
            return false;
        }
        return $open;
    }
    add_filter( 'comments_open', 'close_comment_form', 10 , 2 );

    Solution 2
    Can be used to hide the comment form via display: none; on CSS selector #HIDEcommentform:

    function my_comment_form_defaults($defaults) {
        $defaults['id_form'] = 'HIDEcommentform';
        return $defaults;
    }
    add_filter('comment_form_defaults', 'my_comment_form_defaults');

    In case someone has a solution for specifically targeting the comment form itself, via an update-proof functions file, then I’d love to hear about it.

    Thanks again,

    Ralph

    #348375

    Hi!

    If you want to make it update proof then I would create a child theme and move the comments.php template into it.

    Also, if your just wanting to remove the comment form on some posts then when you edit the post you can uncheck the “Allow comments” option. There is also an option for closing posts for future comments based on how old the post is in Dashboard > Settings > Discussion. This will create a “Comments are closed” text to display instead of the comment form but you can hide that with CSS if you wish.

    Cheers!
    Elliott

    • This reply was modified 9 years, 11 months ago by Elliott.
    #348852

    Hi Elliott,

    The reason I need to mod the comments part, is because of a special kind of post. I actually ended up creating a custom post type for this, which is actually way better than sticking to the standard WP post type. And I gave this custom post type its own file based on the original comments.php file. So now I can edit both the single-costum_post.php file plus the relating comments file, without touching Enfold’s core files. So it has pretty much the same result as a child theme, which is great!

    Also, I noticed that when using a check resulting in comments_open() = false, the comment count is actually displayed when the comment count is greater than 0. So, in a comment count is greater than 0 situation, only the comment form will be hidden, while the comments and the comment count will be displayed. The reason I thought that not only the comment form was hidden but the comment count as well, is because I only tested in a zero comment situation. Had I tested a comments_open() function in a comment count is greater than 0 situation, only the comment form would have been hidden. I’m sorry for not figuring that out sooner!

    Conclusion: Solution 1 is definitely suitable for hiding the comment form itself. And then, as per your suggestion, the “Comments are closed” text could be hidden using some CSS.

    Thank you very much for your time and patience!

    Kind regards,

    Ralph

    #349116

    Hi!

    Your welcome. Let us know if you have any other questions.

    Best regards,
    Elliott

    • This reply was modified 9 years, 11 months ago by Elliott.
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.