Display Pingbacks on WordPress Posts with Disqus Comment System

Pingbacks and trackbacks are no longer supported in Disqus 2012.

Mentions via twitter are, but not pingbacks or trackbacks. The pingbacks are still being stored in the native WordPress database.
After a little searching and a little PHP, I managed to put together something that looks fairly decent. And it sits right above the Disqus comments. Or you could move it below the Disqus comments.


Disqus Pingbacks

Some of this code is taken from here: http://www.saphod.net. So I want to give him a shout out.
But I took his code and added some additional things.

Basically I added a few more columns in his select statement and then echo out comment_content, as well as using the substr and strrpos functions to make it shorter and only cut off the summary after a specified amount of characters and required blank space. I also select the ping date to echo out as well.

I always recommend backing up these files somewhere before editing them.

Step 1

Locate in your single.php file a line that looks like or is the same as this:

[php]<?php comments_template(); ?>[/php]

Step 2

Then insert this right above it. There might be a div in there too you want to dump this on top of.

[php]<?php DisplayPingTrackbacks(); ?>[/php]

Step 3

Go into your functions.php file or your theme’s function file and insert this at the bottom.

[php]function DisplayPingTrackbacks() {

// Do not do anything if Disqus is not installed
if(!dsq_is_installed()) return;

$current_post_ID = get_the_ID();

global $wpdb;

$sql = "SELECT comment_author_url, comment_date, comment_content, comment_author FROM $wpdb->comments WHERE comment_post_ID = $current_post_ID AND comment_approved = ‘1’ AND (comment_type = ‘pingback’ OR comment_type = ‘trackback’) ORDER BY comment_date ASC";

if ($post_pingtrackbacks = $wpdb->get_results($sql) ) {

$number_of_pingtrackbacks = count($post_pingtrackbacks);

if ($number_of_pingtrackbacks == 1) {
echo "<div id=’pingtrackback’><h3 style=’font-size:16px;margin-bottom:10px’>One Pingback/Trackback</h3><ul>";
} else {
echo "<div id=’pingtrackback’><h3 style=’font-size:16px;margin-bottom:10px’>" . $number_of_pingtrackbacks . " Pingbacks/Trackbacks</h3><ul>";

foreach ($post_pingtrackbacks as $post_pingtrackback) {

echo "<strong>";
echo date( ‘d F Y \a\t g:ma’, strtotime( $post_pingtrackback->comment_date ));
echo "</strong><br />";
$comment_summary = $post_pingtrackback->comment_content;
echo substr( $comment_summary, 0, strrpos( substr( $comment_summary, 0, 90), ‘ ‘ ) ) . ‘ …’;

echo "\n<li><a href=’";
echo $post_pingtrackback->comment_author_url;
echo "’>";
$author = $post_pingtrackback->comment_author;
echo html_entity_decode($author);
echo "</a>";
echo "</li>";
echo "</ul></div>";

And that’s it! You should now be able to see your pingbacks on your posts, alongside the Disqus Comment System. Enjoy!


Thomas Spear has taken all of this and released a WordPress plugin that will do this. Check it out! http://wordpress.org/extend/plugins/force-ping-display-with-disqus/

  1. Posted by IslandNature
    • Posted by Brian Jackson
  2. Posted by Radu Tanasescu
  3. Posted by Talton
    • Posted by Brian Jackson
  4. Posted by flapane
  5. Posted by Dream Secret
  6. Posted by Zilla of the Resistance
    • Posted by Brian Jackson
      • Posted by Zilla of the Resistance
        • Posted by Brian Jackson
          • Posted by Zilla of the Resistance
  7. Posted by fooduciary
    • Posted by Brian Jackson
  8. Posted by Brian Jackson
  9. Posted by ThecaTTony
  10. Posted by Momir Nikolajevic
  11. Posted by LD Jackson
  12. Posted by LD Jackson
    • Posted by Brian Jackson
      • Posted by LD Jackson
  13. Posted by Brian Jackson
  14. Posted by Tae-Woo Noh
  15. Posted by Paul Braren
    • Posted by Brian Jackson
      • Posted by Paul Braren
      • Posted by piyushp
  16. Posted by Dominik

Add Your Comment