Skip to content

Instantly share code, notes, and snippets.

@raideus
Created May 10, 2012 22:24
Show Gist options
  • Save raideus/2656287 to your computer and use it in GitHub Desktop.
Save raideus/2656287 to your computer and use it in GitHub Desktop.
WordPress Absolute Sidebar URLs
<?php
/* --------------------------------------------------------------------------------
Add Shortcode Support in Widgets
** Props to http://hackadelic.com/the-right-way-to-shortcodize-wordpress-widgets
-----------------------------------------------------------------------------------*/
if ( !is_admin() ):
add_filter('widget_text', 'do_shortcode', 11);
endif;
/* --------------------------------------------------------------------------------
Absolute URL Shortcode
-------------------------------------------------------------------------------- */
function my_absolute_url($atts, $content="") {
extract(shortcode_atts(array(
'path' => '/', // Defaults to the site's root URL if no path is given
), $atts));
$url = get_bloginfo('url');
$url .= "{$path}"; // Build the URL
if ( $content != "" ) { /* If content is entered inside the shortcode,
return a full link using the content as the link text*/
$output = "<a href='";
$output .= $url;
$output .= "'>";
$output .= $content;
$output .= "</a>";
} else { // Otherwise just output the URL itself
$output = $url;
}
return $output;
}
add_shortcode('link', 'my_absolute_url');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment