Skip to content

Commit

Permalink
Move check for comments being open & if comments, then calling commen…
Browse files Browse the repository at this point in the history
…ts_template() to a template tag
  • Loading branch information
bradp committed Jun 15, 2021
1 parent abb4de7 commit 37f062c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
11 changes: 11 additions & 0 deletions inc/template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,14 @@ function _s_display_mobile_menu() {
</nav>
<?php
}

/**
* Display the comments if the count is more than 0.
*
* @author WebDevStudios
*/
function _s_display_comments() {
if ( comments_open() || get_comments_number() ) {
comments_template();
}
}
5 changes: 1 addition & 4 deletions single.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

the_post_navigation();

// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
_s_display_comments();

endwhile; // End of the loop.
?>
Expand Down
5 changes: 1 addition & 4 deletions template-sidebar-right.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@

get_template_part( 'template-parts/content', 'page' );

// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
_s_display_comments();

endwhile; // End of the loop.
?>
Expand Down

0 comments on commit 37f062c

Please sign in to comment.