Comments are empty in WordPress

Despite that I have added the <?php comments_template(); ?> to single.php it seems like it’s not working! I’m note sure, but why are the comments in the list of comments to be approved empty? The fields for name, email and URL and the content are empty for each comment.

Should the wp-comments-post.php be located together with the rest of the theme files or should it be together with the main files?

Read More

What could be the cause of this problem?

Related posts

Leave a Reply

1 comment

  1. The function comments_template() looks for a file called comments.php in the root of your themes directory. The code inside comments.php should look like the following:

    <!-- Display the comments -->
    <?php if($comments) : ?>
        <ol>
        <?php foreach($comments as $comment) : ?>
            <li id="comment-<?php comment_ID(); ?>">
                <?php if ($comment->comment_approved == '0') : ?>
                    <p>Your comment is awaiting approval</p>
                <?php endif; ?>
                <?php comment_text(); ?>
                <cite><?php comment_type(); ?> by <?php comment_author_link(); ?> on <?php comment_date(); ?> at <?php comment_time(); ?></cite>
            </li>
        <?php endforeach; ?>
        </ol>
    <?php else : ?>
        <p>No comments yet</p>
    <?php endif; ?>
    
    <!-- Display the form -->
    
    <?php if(comments_open()) : ?>
    <?php if(get_option('comment_registration') && !$user_ID) : ?>
        <p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged in</a> to post a comment.</p><?php else : ?>
        <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
            <?php if($user_ID) : ?>
                <p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="Log out of this account">Log out &raquo;</a></p>
            <?php else : ?>
                <p><input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" />
                <label for="author"><small>Name <?php if($req) echo "(required)"; ?></small></label></p>
                <p><input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" />
                <label for="email"><small>Mail (will not be published) <?php if($req) echo "(required)"; ?></small></label></p>
                <p><input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" />
                <label for="url"><small>Website</small></label></p>
            <?php endif; ?>
        </form>
    <?php endif; ?>
    <?php else : ?>
        <p>The comments are closed.</p>
     <?php endif; ?>
    

    however, if you have a different theme directory layout, for example a custom comments.php, you can pass its path in as the funcion parameter. For example, if your theme had a modules direcotry:

    <?php comments_template('modules/custom-comments.php'); ?>
    

    Conclusion

    This could be a code problem or a misuse of the comments_template() function. I recommend you don’t change any WordPress code as it will just be overriden by future updates.

    This answer is based on: https://codex.wordpress.org/Function_Reference/comments_template

    Code Drops taken from:

    http://code.tutsplus.com/articles/unraveling-the-secrets-of-wordpress-commentsphp-file–net-28