How to Display Links with Description in WordPress

Snippets by IsItWP

Are you looking for a way to specify a category using a custom field thecat to display a listing of links / bookmarks? While there’s probably a plugin for this, we have created a quick code snippet that you can use to display links with description in WordPress.


All you have to do is add this code to your theme’s single.php file:

<?php $theCat = get_post_meta($post->ID, 'thecat', true); ?>
				$bookmarks = array();
				$bookmarks = get_bookmarks("category=$theCat");
			if ($bookmarks[0] != '') { ?>

			<?php foreach ( $bookmarks as $bookmark ) {?>
			<tr <?php if($i%2 == 0){ ?> class="odd"<?php $i++; }else{ $i++; } ?>>
				<td><a title="<?php echo $bookmark->link_description; ?>" href="<?php echo clean_url($bookmark->link_url); ?>"><?php echo $bookmark->link_name; echo $bookmarks->term_id; ?></a></td>
				<td><?php echo $bookmark->link_description; ?></td>
			<?php }} ?>

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 23 best WordPress themes for non-profits and how to track affiliate links in Google Analytics.

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!
[63% OFF Today!]
[63% OFF Today!]
[63% OFF Today!]
[63% OFF Today!]
[63% OFF Today!]
[63% OFF Today!]
[60% OFF Today!]
[60% OFF Today!]
[50% OFF Today!]
[50% OFF Today!]