Last active
August 29, 2015 14:08
-
-
Save jrobinsonc/51f22866552407df7aa1 to your computer and use it in GitHub Desktop.
Wordpress shortcode: get_url - Return an absolute URL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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