I was recently having problems with the Blogroll Links Favicons WordPress plugin. The plugin gets the favicon for all the links that you have displayed on any given page using the WordPress links system. The problem was that the standard way the plugin does this is to add a new anchor link inside the list-item for each link. This was a problem for me because the anchor links were styled, so when I added the plugin everything was messed up.

I thought it would be better if the plugin just set the background image of the anchor link that was already there to the favicon and indented the text of the link. I’ve sent an email to the author of the plugin requesting that he make this the default way to display the favicons, but just incase that doesn’t happen, here’s the code that makes it happen:

$str = explode(‘<li>’, $v);
$a = explode(‘ ‘, $str[1]); // Explode the anchor link
$new_bookmark = ‘<li><a style="background: url(‘. $favicon.’) left center no-repeat; -webkit-background-size: 16px; -moz-background-size: 16px; text-indent: 20px;" ‘; // Setup the background image on the link
if(!empty($favicon) || !empty($default_favicon)){
if(!empty($favicon)) {
$new_bookmark .= ‘<a href="’.$bookmark_fullurl.’"><img style="vertical-align: text-top;width:16px;height:16px" src="’.$favicon.’" alt="" /></a> ‘;
} else if (!empty($default_favicon)) {
$new_bookmark .= ‘<a href="’.$bookmark_fullurl.’"><img style="vertical-align: text-top;width:16px;height:16px" src="’.$default_favicon.’" alt="" /></a> ‘;

//Get the rest of the pieces of the link
foreach($a as $b) {
if($b != ‘<a’) {
$new_bookmark .= $b . ‘ ‘;
$bookmark_arr[$k] = $new_bookmark;

You can obviously remove that big chunk in the middle that’s commented out. I just included that so it would be easier to see what to replace. The first and last lines of this example code are the same that are in the actual plugin, also as a reference.