in Tips and Tricks, WordPress

Show/Hide comment status text in wordpress

I am again confused if my post title is perfect or not 🙁 So let me explain, sometimes we disable comment for any post or page and at last the text shows “Comments are closed” or something else in different ways. But in commercial projects we need to follow some good design where in some posts or pages we may need to enable comment or not. So, let’s put a trick in theme to show the comment text(comment status in more smart way)

In latest wordpress version the loop is in the loop.php file in the theme folder. So for comment we will get this line

[code language=”php”]
<?php comments_template( ”, true ); ?
[/code]

But how about we put

[code language=”php”]
<?php if($post->comment_status == "open"){comments_template( ”, true );} ?>
[/code]

That means if comment is off then we will not show any text like “Comments are closed” . I strongly believe this trick will make the design clean in some condition 😛

Thank you

Comments are closed.