DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

Some days ago, I shown you how to save time by using WordPress shortcodes. Do you know that WordPress shortcodes can handles attributes? Here’s a recipes about it.

Adding attributes to your shortcodes isn’t that hard. First, make sure that you have read and understand this recipe about creating shortcodes.

Paste the following code on the functions.php file from your theme.

function myUrl($atts, $content = null) {
		"href" => 'http://'
	), $atts));
	return '<a href="'.$href.'">'.$content.'</a>';
add_shortcode("url", "myUrl");

As you can see on the above code, I have defined a default value for the href attribute on line 3. I’m using this value on the last line, as the value of the html href attribute.

When you’re writing a post/page, insert the following code in the html editor:

[url href="http://www.wprecipes.com"]WordPress recipes[/url]

It will display a link, titled WordPress recipes to http://www.wprecipes.com.

One Comment

  1. It’s just basic syntax same as in codex, nothing more

Leave a Comment

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