Skip to content

WordPress Bookmark Short Code for Links

Here is a useful little WordPress shortcode that some might find helpful. It is a ‘bookmark’ code for accessing links in the Link Manager of WordPress from within your posts or pages. WordPress shortcodes are handy post editing tools to speed up the writing process, especially for something like links that require a fair bit of HTML coding. Using a shortcode can allow you to get consistency in your link output throughout your posts for regularly used links.

/*------------------------------------------------------------------------*/
//	Add bookmark shortcode for links stored in the Link Manager
//	Usage: [bookmark id="link ID" text="usage text for link"]
/*------------------------------------------------------------------------*/
function do_bookmark( $atts )
{
	extract( shortcode_atts( array(
		'id'	=> 1,
		'text'	=> ""  // default value if none supplied
	 ), $atts ));

	if ( $text )
	{
		$bm = get_bookmark( (int)$id );
		return "<a href='$bm->link_url' title='External link to: $bm->link_name -- $bm->link_description'>$text</a>";
	}
	else	// if no text supplied, use the link name from the Link Manager
	{
		$bm = get_bookmark( (int)$id );
		return "<a href='$bm->link_url' title='External link to: $bm->link_name -- $bm->link_description'>$bm->link_name</a>";
	}
}
add_shortcode( 'bookmark', 'do_bookmark' );

Place the above code in your functions.php file and then from within your posts you can use something like:

[bookmark id="293" text="WordPress"] is great blogging software!

and your final post output complete with title popups will look like:

[bookmark id=”21″ text=”WordPress”] is great blogging software!

Enjoy!

Other people's views

Comments are closed, sorry.