How to Use WordPress for Bookmarking
After Ma.gnolia went down I was so disappointed that I decided to take matters into my own hands. I thought, why not use WordPress to store my bookmarks. It has all the neat features of most popular bookmarking sites, and even some more (XFN, for example).
Of course, I could just post a link whenever I saw one but it panged me to think that I would be putting to waste that wonderful link schema that the folks at WordPress have put so much thought into. And then Smashing Magazine reminded me about shortcodes. I had used them before in plugins but I never thought about just adding one off short codes to my functions.php file.
It turns out that this was the perfect solution to my problem. With one tiny little shortcode I was able to utilize the bookmarks system in WordPress and publish my links as normal. Here is how I did it.
1. The shortcode code
First you want to start by adding the following code somewhere in your functions.php file.
-
/**
-
* Get a bookmark and display it
-
*
-
* usage: [magnolia id="bookmarkid"]
-
*
-
* @return string
-
*/
-
function magnolia_rip($atts) {
-
'ids' => '1',
-
), $atts));
-
-
$bookmarks = '';
-
-
foreach ($idarr as $id) {
-
$bookmark = get_bookmark($id,ARRAY_A);
-
-
$bookmarks .= <<<LINK
-
<div class="magnolia_rip">
-
<p class="notes">$link_notes</p>
-
<p><a class="more-link" rel="$link_rel" href="$link_url" title="$link_description">$link_name</a></p>
-
</div>
-
LINK;
-
}
-
-
return $bookmarks;
-
}
-
add_shortcode('magnolia', 'magnolia_rip');
I'll skip the details on how shortcodes work, the Smashing Magazine post does a great job of summing that up. However, I do want to explain the bookmark stuff.
We start by passing in the id or comma separated list of ids through the shortcode. They get put into an array where they are iterated. For each id we call the get_bookmark method, which is currently undocumented. It returns an object or array with all the values from the links table in your WordPress installation. The ARRAY_A parameter tells the method to return an associative array.
Here are all the fields in the links table:
link_idlink_urllink_namelink_imagelink_targetlink_categorylink_descriptionlink_visiblelink_ownerlink_ratinglink_updatedlink_rellink_noteslink_rss
I have used the extract() method to convert each key (field) in the returned array to a variable. That's probably not the best idea for performance reasons, but for demonstrational purposes it's nice and clean. Next, I create a div with some paragraphs and a link. This is the part where you can customize to your hearts content. I just went with something basic.
2. Add a link
Now all you need to do is head over to your links page in the WP admin and add a link. I put mine in a category called bookmarks just to keep things organized. You can go crazy here if you want. Once you've saved the link make sure to get the ID for it.
The ID isn't anywhere obvious, unfortunately, which makes this technique feel a little hacky. Regardless, if you go back to the links page and hover over the title of your link you will see something like this in your status bar at the end of the URL:
-
link_id=165
Just take note of the id, you'll need it for the next step.
3. Write your post
Finally, lets post the link to the blog using the shortcode we created earlier. Start a new post and add the following:
-
[magnolia ids="165"]
That's it! Now save your post and basque in the glory of your ingenuity!
Caveats
There is one caveat that I can think of. The RSS feed will not publish the generated text. So you'll only have titles for those posts unless you add more text to the body of your post.
This is a great way to use an often under-utilized feature of WordPress. It is also fun to host and publish your own bookmarks for people to see. Let me know how it works for you!
Update: After more careful testing I realized that the full text does, in fact, show up in RSS. So there you have it, if you want to post your bookmarks to your site nothing is standing in your way!





Want an avatar? Get a gravatar! • You can link to this comment
Very nice, thank you.
Your last point: caveats of RSS – I think that can probably be easily solved with a mod to the functions.php file. The always clever, Jean-Baptiste Jung wrote up another great post at Smashing Magazine – a variation of #3 might do the trick?
10 Useful RSS Hacks for WordPress
Want an avatar? Get a gravatar! • You can link to this comment
Doesn’t look like it’s an issue anymore. I just double checked the feed and it does appear to be displaying properly.
Want an avatar? Get a gravatar! • You can link to this comment
Very nice, i’ll implement this to my page.
Thank you Dustin! i also enjoy reading your blog, very informative and inspiring.
Want an avatar? Get a gravatar! • You can link to this comment
Glad you liked it. Great design on your site!