Simple URL Shortcodes for WordPress

Doing web development on testing servers is a common practice. Many of these servers have addresses that are an ip address with a user name. For example, these development addresses can be something like:

http://12.34.56.789/~username/

The problem with this is that it throws off your relative URL structure. You can use /page because it will go to http://12.34.56.789/page. You can’t use /~username/page because it won’t work once you go live. This is not a problem in php files because you simply call the site URL dynamically. In the content, however, you can’t do that.

Good news, everyone! Good news everyone!

The solution is simple.

Here is the code for a simple shortcode you can use in your functions file for your sites. that will allow you to simply type [url]/page.

// Adds Shortcode [url]
function display_url( $atts ) {
	return get_site_url();
}
add_shortcode( 'url', 'display_url' );

You are welcome…

Leave a comment

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