By Sanjeev Shrivastava Our Bestseller: WordPress Themes
Well we all know WordPress is highly customizable and can be customized up to a great extent. WordPress is also famous for a huge repository of plugins which provides you plugins for everything. Think about any functionality that you want in your WordPress site and either Google it or ask any WordPress expert, you will be answered like “there’s a cool plugin for that”. Using plugin in your WordPress website is the easiest way of adding new functionality. Most of the people use plugins but there are few disadvantages of using plugins like: few heavy plugins may make your website slow, free plugins may contain encrypted code which may harm your website etc.
If you don’t want to use these free plugins then you will need to code on your own. Yes customize your WordPress website by coding. In this tutorial I will explain you how you can customize WordPress default comments yourself without using any external plugin:
Lets Understand WordPress Comment system:The most basic function which is responsible for displaying comment box is comment_form(). You will see a call to this function in bottom section of “comments.php” file. Usually single.php, page.php, contact form template of theme call comment_form() function to display comment box. Below is the snapshot of twenty twelve theme’s “comments.php”.
More Detailsabout this function.
But the default use is just
When you call this function without any argument then comment box (twenty twelve theme) looks like this:
Parameters are just optional. In its default call it displays fields like name (required), email (required), website, and comment.
Let’s see how you can pass parameters and change your default comment form. In first parameter ‘$args’ (an array) you can pass various important arguments such as fields, title_reply, label_submit etc. These arguments will help you change your default comment form.
fields – Lets you display fields of your choice in comment form. title_reply – This argument changes title of reply, by default you will see “ Leave a reply ”. label_submit – it changes text written on Submit button. comment_field – it is responsibe for text area and label of comment body.Just for a small example let’s consider I want to change default comment box title which is “Leave a reply” in our case. Then I will pass my new title as an argument to comments_form(); function:
'Got Something To Say:')); ?>Now comment box title will be
“Got Something To Say” .
Now what if you have to add/remove fields from default contact form to change the feel of your comment box? I am eliminating website field from default comment box by playing with ‘ fields ’ argument:
'Got Something To Say:', 'fields' => apply_filters( 'comment_form_default_fields', array( 'author' => '' . ' ' . __( 'Your Good Name' ) . '' . ( $req ? ' * ' : '' ) . '
', 'email' => '' . ' ' . __( 'Your Email Please' ) . '' . ( $req ? ' * ' : '' ) . ' '.'
', 'url' => '' ) ), 'comment_field' => '' . ' ' . __( 'Let us know what you have to say:' ) . '' . ' ' . '
', 'comment_notes_after' => '', ); comment_form($comment_args); ?>Finally our contact form of twenty twelve theme looks like this:
Conclusion:This tutorial covered basics of customizing comment box, a lot more can be done in order to change the appearance of the comment form as well. WordPress provides us hooks and filters to add remove fields and customize our form up to a great extent. Comments are very important for any blog to interact with their audience so I recommend every blogger and website owner to change their WordPress default comment system and make it more creative and pleasing.
About Sanjeev Shrivastava
author
Sanjeev loves web and his blog InfoTuts. His curiosity to know how things actually work keeps him active and inspires him to learn new things. He loves to help people. You can join him Here
Comments and Responses
0 nhận xét:
Đăng nhận xét