How to check if post comment is enabled or not in WordPress

This article was written by in April 10, 2015, & may not be posted on other sites!
Original source url for this article: How to check if post comment is enabled or not in WordPress

Check if post comment is enabled or not in WordPress for inddividual post or page?
In every post or page you can enable or disable comments either for each post individually by checking the comments box, or in admin > settings. This is how to check if post comment is enabled or not on the current post or page in WordPress when using php:

How to check if post comment is enabled or not in WordPress

 

How to check if post comment is enabled or not in WordPress

To check if post comment is enabled or not in WordPress for the current post, use this php code in any template or theme file:
<? if (comments_open()){ ?>
//your code
<? } ?>

This php code will also work:
<?php if ('open' == $post->comment_status) : ?>
//your code
<?php endif;?>

 

 

Spread the word

Facebooktwittergoogle_pluslinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *