How to create a shortcode to display the WordPress site url

Shortcodes are a very useful tool when using WordPress. There are often things you may do a lot and using a shortcode helps make it so you can use one instead of retyping a lot of content. Also, if you are a web developer, you may be creating WordPress themes/sites on a development server that will later be transferred to a client’s server. When doing this, the url during development may not be the same as will be after it is transferred over to the client’s live site and server. This can cause extra work after making the transfer editing links and other text that may have displayed the url. You can use a shortcode to find the current site url and display it based on the url the WordPress theme is currently installed on, so no matter where the theme is used, it will display the correct url, which means you won’t have to change it if you move the theme to a new url. Just add this WordPress Code Snippet to the functions.php file in your current WordPress theme in order to create a shortcode to display the WordPress site’s current url.

 * Get site url for links 
 * @author
 * @link
function url_shortcode() {
return get_bloginfo('url');

That’s it, now you can just type [url] anywhere you want the url to display throughout the site You can use this shortcode inside a link or other code as well(Can be used for the “Home” link in a navigation bar for example). Hope this helps, enjoy!

   Related Sponsored Links

Disclaimer: The information contained in this website is for general information purposes only and in no event will this site or its owners be liable for any losses or damages associated with your use of our site or content. Click here to see our full Disclaimer.


  1. Thanks for your example of building a shortcode.  It provide a good template for build one for displaying permalinks of posts. by using get_permalink()

  2. webmasterintexas says:

    This is not working for me. It is still spitting out [url] in firebug.

  3. Worked like a charm. Thanks for posting!

Leave a Comment