Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Last active August 29, 2015 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrobinsonc/51f22866552407df7aa1 to your computer and use it in GitHub Desktop.
Save jrobinsonc/51f22866552407df7aa1 to your computer and use it in GitHub Desktop.
Wordpress shortcode: get_url - Return an absolute URL.
<?php
/**
* Return an absolute URL.
*
* Usage:
* [get_url page=<page id>]
*
* or
*
* [get_url path=<path>]
* <path> can be: uploads, theme or site.
*
* @author JoseRobinson.com
* @link https://gist.github.com/jrobinsonc/51f22866552407df7aa1
*/
function get_url_shortcode($attrs)
{
if (isset($attrs['page']))
{
$url = get_page_uri($attrs['page']);
}
elseif (isset($attrs['path']))
{
switch ($attrs['path'])
{
case 'uploads':
$upload_dir = wp_upload_dir();
$url = $upload_dir['baseurl'];
break;
case 'theme':
$url = get_template_directory_uri();
break;
case 'site':
$url = get_bloginfo('url');
break;
}
}
return isset($url)? $url : '';
}
add_shortcode('get_url', 'get_url_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment