Show Link Notes

The link Description field in WordPress is limited to 255 characters. If you’re creating a link directory with WordPress or just want to leave a longer description, you should use the Notes field, which can contain significantly more text. Unfortunately, by default, wp_list_bookmarks($args) does not allow for the display of Notes. With a bit of PHP hackery, you can make the template display them.

Open wp-includes/bookmark-template.php in your favorite text editor or IDE. Scroll down to function _walk_bookmarks(), which is, approximately, on line 51. You’ll see an array named $defaults. We want to edit this to include a new default: show or hide Notes. By default, Notes should be hidden, to prevent any kind of template jinkiness with sidebar Blogrolls or link categories found elsewhere. Replace the array with the following

$defaults = array(
	'show_updated' = 0,
	'show_description' = 0,
	'show_images' = 1,
	'show_name' = 0,
	'before' = '<li>',
	'after' = '</li>'
	'between' = '\n',
	'show_rating' = 0,
	'link_before' = '',
	'link_after' = '',
	'show_notes' = 0
);

Now, search for $output .= ‘</a>’;. Directly after this, insert the following

if($bookmark->link_notes != null && $show_notes) {
$output .= "<p>".$bookmark->link_notes."</p>";
}

If the bookmark has a Note, and the page wants the Notes displayed, display them. Once this is in place, open whatever page is displaying your links and, within the $args array, add ‘show_notes’ => 1 at the very end.

Now’s a good time to note that I made some other changes to my wp-includes/bookmark-template.php which I found particularly useful. By default, the code displays the $link_before variable after the a element.

$output .= '<a href="'.$the_link.'"'.$rel.$title.$target.'>';
$output .= $link_before;

I reversed these. It just seems more logical that $link_before would represent something that occurs, well, before the link.

$output .= $link_before;
$output .= '<a href="'.$the_link.'"'.$rel.$title.$target.'>';

Likewise, I reversed the second set, so $link_after actually occurs after the link

$output .= $link_after;
$output .= '</a>';

If you’re not interested in performing PHP hackery, here are a copy of the two files, complete with the edits listed here and a before_notes and after_notes option. Also included is a template for a links page. I make no guarantees that these files will work for you. Back up your existing files first.

Download Display Notes.zip.

This entry was posted in Code. Bookmark the permalink.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>