banner



How To Add Cmment Box In Blog Post In Wordpress

How To Add Comment Box In WordPress Theme With The Clean Code?

September 27th, 2016 | by Ravi Chahar || 9 Comments |

how to add comment box in wordpress theme

One of the hardest parts of a WordPress Theme is the comments box. Do you want to know how to add comment box in WordPress Theme?

You all know that developing a WordPress Theme isn't a piece of cake. It requires expertise and devotion to keep going with the codes.

You can get the WordPress comment form with one line of the code. But to make it function properly, you have to write many lines of the codes.

Whether you create a brand new theme or you create a child theme. You have to add an author box, search box, comment box etc.

Your Question "how to add comment box in WordPress Theme has an answer".

In this tutorial, I will provide the clean code with the possible security. Adding a comment box in WordPress would take you to the completion of your WordPress Theme.

I have experienced that it would take quite a few time to understand the coding of this comment box. If you want to use the default WordPress comment box to your website then it's the best way.

There are many other comment systems like Disqus and Facebook.

What Should You Do To Add Comment Box In WordPress?

If you are aware of WordPress Theme file structure then you would also know about a file named " comments.php ". In each WordPress Theme, this file is present which controls the functioning and the structure of the comment box.

If you are developing a new theme or adding a comment box in an old theme, you have to create a new file " comments.php " in the theme folder.

You can edit the theme from the theme editor or using the cPanel.

Add the code in the file.

Let me provide you the code.

<?php
      if ( post_password_required() ) {
          return;
      }
?>

<div id="comments" class="comments-area">

<?php
      if (have_comments() ) :
     //We have comments
?>

<h2 class="comment-title">

<?php
printf(
esc_html( _nx( 'One Comment', '%1$s comments', get_comments_number(), 'comments title', 'blogginglovetheme') ),
number_format_i18n( get_comments_number() )
);
?>

</h2>

<ol class="comment-list">
<?php
$args =array ( 'walker' => null, 'max_depth' => ", 'style' => 'ol', 'callback' => null, 'end-callback' => null, 'type' => 'all', 'reply_text' => 'Reply', 'page' => ", 'per_page' => ", 'avatar_size' => '48', 'short_ping' => false, 'echo' => true );
wp_list_comments($args);
?>
</ol>

<?php
if( !comments_open() && get_comments_number() ):
?>

<p class="no-comments"><?php esc_html_e( 'Comments are closed.', 'blogginglovetheme'); ?></p>

<?php
endif;
?>
<?php
endif;
?>
<?php comment_form(); ?>

</div>

This code will generate a comment form and all its functionalities. Every website has its different comment box. Depending on your choice, you can design the comment form using CSS.

Before saving, it is recommended to arrange the code properly. Use the "TAB" coding to maintain spacing and the size of the file. You just have to arrange the code properly.

It's important to add the clean code so that anyone can understand it.

There will be a heading showing the number of comments. The comment author and the possible details of the author with the date.

If you want to show the date according to you then you can change it using different PHP date rules.

When you start developing a WordPress Theme, you install WordPress on Xampp server and feel happy to build each segment of the theme. But when the time comes to add comment box in WordPress, it would be really hard to understand its concept.

The question "how to add comment box in WordPress Theme" would make you sick. And the most disappointing part is that you don't find any relevant code to solve the problem.

But here I am with you all, just copy the code shown above and paste it in the comments.php file of the theme.

NOTE:- This comment box code won't show the comment box. You have to call the template wherever you want to show it.

If you want to show the comment box under the single post or the pages, you have to call this comments' template.

Let me provide you the code.

<?php comments_template(); ?>

Add this code in the single.php if you want to add comment box in WordPress single posts. If you want to show the comment box on the pages then you can add this code in page.php file.

It's your choice whether you want to show the comment's box on the pages or not. You may have noticed that most of the websites don't have the comments on their "About Us" page.

Are You Still Searching To Know How To Add Comment Box In WordPress Theme?

Web Development is an amazing field and you would be glad to know the code to add comment box in WordPress theme. As of my experience, adding a comment box in WordPress Theme is one of the complicated parts.

There are many conditions to build. Like if you have comments then what to provide, if you don't have the comments then what.

The code shown in this tutorial can be used in any WordPress Theme. There are many inbuilt IDs and classes of the HTML elements to target for the design of the comment box. You can provide a beautiful design to your comment box.

How To Add Cmment Box In Blog Post In Wordpress

Source: https://www.blogginglove.com/how-to-add-comment-box-in-wordpress-theme/

Posted by: bairdanowbod.blogspot.com

0 Response to "How To Add Cmment Box In Blog Post In Wordpress"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel