WordPress fusion theme: twitter widget link problem


The twitter sidebar widget in the fusion theme of wordpress shows weird in Firefox browser, due to the encoding of the double quotes in the href attribute. For example, a link from a twitter post shows like this in source:

  1. <a href=&quot;http://bit.ly/foo123&quot;>bar</a>

Safari in quite intelligent regarding this and displays the links right.

A look in the code revealed that the output from twitter webservice call is not completely decoded. The function fusion_TwitterWidget() in wp-content/themes/fusion/functions.php looks like this after an easy fix:

  1. // theme widget: Twitter
  2. function fusion_TwitterWidget($args){
  3.  extract($args);
  4.  echo $before_widget;
  5.  print $before_title.__(‘Twitter posts’,'fusion’).$after_title; ?>
  6.  
  7.  <?php
  8.  $username = get_option(‘fusion_twitterid’);
  9.  $limit = get_option(‘fusion_twitterentries’);
  10.  if($username<>) {
  11.   $feed = file_get_contents("http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=" . $limit);
  12.  
  13.   // joyd: fix for the broken hyperlinks of twitter plugin due to encoded quotes
  14.   // $feed = str_replace("&lt;", "< ", $feed);
  15.   // $feed = str_replace("&gt;", ">", $feed);
  16.   $feed = html_entity_decode($feed);
  17.  
  18.   $clean = explode("<content type=\"html\">", $feed);
  19.   $amount = count($clean) - 1;
  20.   print ‘<ul id="twitterupdates">’;
  21.   for ($i = 1; $i < = $amount; $i++) {
  22.    $cleaner = explode("</content>", $clean[$i]);
  23.    print ‘<li class="entry">’;
  24.    echo $cleaner[0];
  25.    print ‘</li>’;
  26.   }
  27.   print ‘</ul>’;
  28.  }
  29.  
  30.  echo $after_widget;
  31. }

Thanks a lot to Francesco to point this out !

,

  1. #1 by Simon on November 13, 2009 - 4:13 pm

    Thanks for the post Joy, but using this code completely stopped my blog from running – something isn’t right here!

    I see on your Fusion sidebar that the links are formatted correctly, yet when i use the code you’ve suggested above, it doesn’t work. In fact, nothing on my blog works!

    Any suggestions? Thanks!

  2. #2 by therider on November 13, 2009 - 4:17 pm

    Simon, can you just try the change I outlined instead of the whole piece of code I posted ? Your plugin could be of later version with more changes.

  3. #3 by deuts on July 29, 2010 - 8:38 pm

    I have tried implementing this fix. And it fixed the wrong url’s in the twitter widget very well. However, it actually broke my blog’s feed in return.

  4. #4 by therider on July 29, 2010 - 9:18 pm

    It is hard to tell if my fix will work with everyone because of continuously changing wordpress software versions. Even a minor change can break a fix done against an older version. I will check if anything breaks when I upgrade my wordpress to latest.

  5. #5 by Programador PHP on December 23, 2010 - 10:12 pm

    Thanks

    Excelent post!!!!

(will not be published)