I'm creating a custom theme for my blog and I've been working on the comments for a while now. I've tried a few different strategies and read a lot of the codex and questions on here but I can't seem to get the comments to work.
I've created a custom comments.php file and placed it in the theme directory but I know it's not even getting included in the blog because I put in some console logs and they are not showing up.
It seems the problem is even more complicated than just that though, because I can get the comment form to show up, but I've tried to enter some test comments and when I click submit on the form, no comments get submitted to the database and it just redirects me to the single.php for the blog entry that I'm trying to comment on.
I've tried copying the comments.php from the 2016 theme but that made no difference either.
I've been following a few different tutorials on how to set this up and I've tried to find my answer in the wordpress codex pages that discuss comments.php but I haven't had any luck. If anyone could take a look at my blog, and let me know where I might be going wrong, I'd really appreciate the help.
I'm calling the comments section with this line of code:
<?php comments_template(); ?>
Here is the code for my custom comments.php:
<?php
if(!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) :
die("You shall not pass!");
endif;
if ( post_password_required() ) {
return;
}
?>
<script type="text/javascript">console.log("Is this thing on?");</script>
<div id="comments" class="comments-area">
<?php if ( have_comments() ) : ?>
<h2 class="comments-title">
<?php
$comments_number = get_comments_number();
if ( 1 === $comments_number ) {
/* translators: %s: post title */
printf( _x( 'One thought on “%s”', 'comments title', 'twentysixteen' ), get_the_title() );
} else {
printf(
/* translators: 1: number of comments, 2: post title */
_nx(
'%1$s thought on “%2$s”',
'%1$s thoughts on “%2$s”',
$comments_number,
'comments title',
'twentysixteen'
),
number_format_i18n( $comments_number ),
get_the_title()
);
}
?>
</h2>
<?php the_comments_navigation(); ?>
<ol class="comment-list">
<?php
wp_list_comments( array(
'style' => 'ol',
'short_ping' => true,
'avatar_size' => 42,
) );
?>
</ol><!-- .comment-list -->
<?php the_comments_navigation(); ?>
<?php endif; // Check for have_comments(). ?>
<?php
// If comments are closed and there are comments, let's leave a little note, shall we?
if ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) :
?>
<p class="no-comments"><?php _e( 'Comments are closed.', 'twentysixteen' ); ?></p>
<?php endif; ?>
<?php
comment_form( array(
'title_reply_before' => '<h2 id="reply-title" class="comment-reply-title">',
'title_reply_after' => '</h2>',
) );
?>
</div><!-- .comments-area -->
If any more code is needed please let me know and I will post it as soon as I can. I'd really like to get to the bottom of this. Thanks in advance!
comments_template()
developer.wordpress.org/reference/functions/comments_template