Customize Display of Comments in Kalin’s Post List and PDF Creation Station

-- Download Customize Display of Comments in Kalin's Post List and PDF Creation Station as PDF --

In version 3.0 of  PDF Creation Station WordPress plugin, and version 3.0 of  Post List, I added a shortcode for post comments that looks like : [post_comments before=”” after=””]. Naturally the biggest issue with this is that some folks want a specific formatting and perhaps other special handling such as removing pingbacks, customizing name/date formatting or dealing with nested comments. Here’s how you can add your own function to handle post comments in the PDF.

Currently in kalins-pdf-creation-station.php, or kalins-post-list.php, you will see a function called commentCallback($matches). This is currently what processes the comments shortcode. You will see the first thing it does is check to see if you have defined your own comment callback function:

if(defined("KALINS_PDF_COMMENT_CALLBACK")){//remove this if statement if you copy this function to use it as a custom comments function
return call_user_func(KALINS_PDF_COMMENT_CALLBACK);

So the first thing you want to do to create your custom comment function is copy this whole function into your wp-config.php file and give it a unique name. You could probably put it somewhere else and this would still work. Then remove the if statement that checks for your custom callback (very important to prevent infinite loop). Then you simply modify it to display the comments however you want.

The final step is to also put this code into your wp-config.php file and replace the name of the function:

define('KALINS_PDF_COMMENT_CALLBACK', 'my_function_name');

Doing this should give you your custom comments display and should remain in effect even after upgrading to a new version of this plugin.

11 thoughts on “Customize Display of Comments in Kalin’s Post List and PDF Creation Station”

  1. Hi Kalin thanks for the plugin it was very use full to me.. I need an image instead of download link. Can you give me any solution for this it will be very helpful.
    Thanks again..

  2. Hi Kalin it was very use full to me thank you very much,

    I need to change the download link to and image, Can you please give me any idea about this it will be very helpfull for me.

    Thanks again..

  3. It is nonetheless an excellent plugin and there’s just no equal out there. Well done Kalin! I hope you will continue to have the motivation to update and improve on it.

    1. Kalin, hi again. In the code below, is there a way to order the comments so that they always show with the oldest on top? At the moment, it defaults to showing the newest comments on top. I have tried adding the Order by DESC, ASC with no luck. Thank you in advance.


      function commentCallback($matches) {

      return call_user_func(KALINS_PDF_COMMENT_CALLBACK);

      global $post;

      $comments = get_comments(‘status=approve&post_id=’ .$post->ID);

      $commentString = $matches[2];

      foreach($comments as $comment) {
      if($comment->comment_author_url == “”){
      $authorString = $comment->comment_author;
      $authorString = ‘comment_author_url .'” >’ .$comment->comment_author .”“;
      $commentString = $commentString .” .$authorString .”- ” .$comment->comment_author_email .” – ” .get_comment_date(null, $comment->comment_ID) .” @ ” .get_comment_date(get_option(‘time_format’), $comment->comment_ID) .”” . $comment->comment_content .””;

      //get_comment_date(‘m-d-Y @ g:i A’, $comment->comment_ID)

      return $commentString .$matches[4];

  4. Hi, have you noticed that your plugin displays the comment author’s email? When that pdf comes out, how can you prevent the email address from being published?

    1. I don’t recall but I would believe it. There’s no options to change that in the UI but I’m sure you could hack the source code quite easily with just a little PHP knowledge.

    2. Actually, now that I look closer, that kind of thing is exactly what I’m explaining how to do on this page 🙂 You still need a little PHP knowledge though.

  5. Hi Kalin,
    As Vuzhe said, what an amazing plugin. We evaluated most of the PDF creation plugins for a WordPress project we’re currently developing, and yours has proven to be the best by far.

    One quick suggestion you may want to consider to make it even better:

    – One of your shortcodes is [post_author], which basically calls the WordPress key “user_login”. This is not necessarily the most attractive way to show a post or page’s author on the PDF, it’s more useful to show the value for “display_name” (so instead of showing “by andresfernandez” it can show “by Andres Fernandez”).

    We modified a line in the plugin file (kalins-pdf-creation-station.php) to accomplish this, but it’d be a great addition to the plug-ins Admin area (allowing users to pick which key to use for [post_author], similar to how you give users the option to pick the post slug for the PDF filename instead of the ID).

    But again, what an amazing and useful plugin. Donation to come!

    1. Hi, thanks. yeah, I noticed that issue a while ago, and I think I forgot to write it down. I want to add a param, so the shortcode would look like [post_author type=”display_name”] so you can choose “display_name”, “user_login”, “ID”, or “profile_url”. I should do this to my Post List plugin too.

  6. Hi Kalin,
    Thanks for a super plug-in. We’ve been using the plugin for about 2 months now with no problems.
    We recently added an events management (Events Manager) plugin to our site which basically lists upcoming events with some details around each event.
    When we try to create the PDF from the events page the PDF file does not have the contents from the page. It only displays the text “CONTENTS”.
    We are fairly new to WordPress and PHP. We took a look at the kalins_pdf_create php file to see if we could find where/how the content is built but unfortunately we have failed so far.
    Is the PDF creator built specifically to exclude content generated by other plug-ins? Where does the value assigned to the $content variable(post_content) come from?


    1. I tried out the Events Manager plugin and used its shortcode feature, which seemed to basically work when I outputted the PDF. The calendar showed up in the PDF, though it didn’t look as pretty as it does on the page. The events page, however, threw an error. It looks like that events page is using form elements, jQuery and other javascript that seems to be just a bit too complicated for the TCPDF engine to handle.

      Don’t forget you also have to have the “Run other plugin shortcodes” and/or “and content filters” checkboxes checked for other plugins to be able to do their thing. I believe they are un-checked by default.

Leave a Reply

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