How To Make Wordpress Comment Quoting Function

January 12th, 2009 by James | This article was viewed 7,607 times.

How To Make Wordpress Comment Quoting Function

It has been some time since I last posted and I was spending my time learning Javascript to implement my first wordpress function (not a plugin). I have decided to create my own Wordpress Comment Quoting System.


This “How To” guide will show you a detailed method to build your own quoting function. I’ve done all the Javascript programming. All you need to do is implement with the step by step guide below. The code isn’t very clean but it does the job without a need of a plugin (I hate plugins so … ).

What is a Comment Quoting Function?

A picture tells a thousand words.

So basically quoting is used to indicate that you are replying to the person’s statement you have quoted. Thus allowing readers to understand who you are replying to and what your comment is all about.

Building your own Wordpress Comment Quoting Function in your Template

I’ve written this in such a way that there is no need to reinstall the plugin and all the tedious stuff when you upgrade your wordpress. All you need to do is,

  1. Do this one-time implementation and when you upgrade your wordpress …
  2. Upload your theme
  3. Activate your theme. And you’re good to go.

PseudoCode of the Function

PseudoCode is a way of describing the flow of the program (in this case, function).

  1. Get comment ID
  2. Get data (Name, Date, Quote and Comments) from the comment ID
  3. Process and separate all the elements stated above
  4. Process the Comments by deleting <blockquotes> and <br />. So only 1 level quoting is allowed.
  5. Put all the quotes into a string
  6. Display the quoted text with Name, Date and Comment in the Comment textarea.

Step By Step Implementation

  1. Create a “js” folder under your theme section (same level as your .CSS file).
  2. In the “js” folder, create a .js file for the comment function you are going to create. eg. “post-comment.js” or anything relevant.
  3. Download/Copy the code I have provided into the .js file you’ve just created in step 2.
  4. Because of the processing part in the javascript code, there is a formula to write your comment. So … Yes you need to edit some stuff in the “comment.php” file.
  5. In the first line of “comment.php”, add this tag <script type=”text/javascript” src=”<?php bloginfo(‘template_url’); ?>/js/post-comment.js”></script>
  6. In the <li></li> tag of comment.php (The formula for the function to work)
    <li>
    <div class=”comment_header”>
    <?php echo get_avatar( $comment, 40 ); ?>
    <cite class=”comment_name”><?php comment_author_link() ?></cite> Says:
    <?php if ($comment->comment_approved == ‘0′) : ?>
    <em>Your comment is awaiting moderation.</em>
    <?php endif; ?>
    <br />
    <small class=”commentmetadata”><a href=”#comment-<?php comment_ID() ?>” title=”" class=”comment_date”><?php comment_date(‘F jS, Y’) ?> at <?php comment_time() ?></a> <?php edit_comment_link(‘edit’,'&nbsp;&nbsp;’,”); ?></small>
    </div>
    <div class=”comment_data”><?php comment_text() ?></div>
    <div class=”comment_function”><a class=”quote_button” style=”text-decoration: none;” href=”javascript:void(0);” onclick=”quotecomment(<?php comment_ID() ?>);” title=”Quote Button”>Quote</a></div>
    </li>
  7. I hope you are still keeping up. The idea is to add all the bolded words above. NOTE: They all must be added or the javascript wouldn’t know where to process the quote.
  8. Style your <blockquote> and Quote Button to look pretty in respect to your theme.

So that’s all for implementing the Wordpress Comment Quoting Function. I hope I did not miss out anything. If I do miss out anything, please leave a comment and I’ll fix it. For the Javascript experts out there, your input to further improving this block of Javascript function would be greatly appreciated as well!

Enjoy Reading? Subscribe to our RSS Feed for future updates.

13 Responses to “How To Make Wordpress Comment Quoting Function”

  1. Frost Fox Says:

    nice one :) im gonna use it for my blog

  2. Gabriel Lai Says:

    Quote(Frost Fox on January 15th, 2009 at 12:30 am):
    nice one :) im gonna use it for my blog

    seems like a good idea :D

  3. Coeneiree Says:

    fascinating and communicative, but would make something more on this topic?

  4. James Wee Says:

    Quote(Coeneiree on February 11th, 2009 at 2:44 pm):
    fascinating and communicative, but would make something more on this topic?

    Yes of course. Given that if I have the time to do it. Why not?

  5. CSS Envy | aSKer Says:

    amazing stuff thanx :)

  6. RaiulBaztepo Says:

    Hello!
    Very Interesting post! Thank you for such interesting resource!
    PS: Sorry for my bad english, I’v just started to learn this language ;)
    See you!
    Your, Raiul Baztepo

  7. James Says:

    Hi Raiul Baztepo, thanks for dropping by and for loving my post. Appreciate it.

  8. Cleasecax Says:

    hmm… love it )

  9. kenteelry Says:

    emm. attractive :)

  10. Geusghegner Says:

    your work is amazing.,

  11. Shanghainese Dumpling Says:

    Cute hehe :) Bookmarked I’ll try it later on my blog

  12. love moneymaker Says:

    Can i use this for blogger as well??

Leave a Reply

Let me notify you when I reply your message. Subscribe to Comment RSS.

Similar Posts Linked To This Article

More Posts
06 Mar - How To Disassemble Laptop (Dell Latitude E4300) | 329 views
28 Jan - Apple iPad “The Future” If Revised | 617 views
31 Dec - How To Import Blog Post Into Facebook Automatically | 1,166 views
30 Dec - Sherlock Holmes 2009 Movie Review | 1,464 views
28 Dec - Dota Hero Guide – Pugna The Oblivion | 2,368 views
24 Dec - Avatar 2009 Movie Review | 1,091 views
21 Dec - A Prologue Of A DotA Gamer | 800 views
18 Dec - Eastern Creek Karting Raceway Experience | 822 views
16 Nov - How Important Is Net Neutrality? | 1,131 views
13 Nov - Buying And Selling Behaviour Reverted? | 1,184 views
27 Oct - If I Have a Million Dollars, I will … | 1,414 views
20 Oct - 10 Ways to Make Facebook a Better Socializing Platform | 1,371 views
01 Oct - ServerFreak User Experience Review | 1,558 views
16 Sep - 1Malaysia F1 Team – Is That Necessary? | 3,684 views
09 Sep - How To Fix Wobbling Screen (Dell Inspiron 6400/E1505) | 7,226 views
  • AhWee Gallery

    Christmas Tree
    Man Made Sakura Tree
    Flower 1 @ Hunter Valley Trip
    Sunset 3
    Darling Harbour on Christmas

Share