URL Shortcodes

Below, you’ll find a detailed guide on how to add the URL Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the URL ShortCodes Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the URL ShortCodes Plugin and the shortcodes it provides:

Plugin Icon
URL ShortCodes

"URL ShortCodes is an innovative WordPress plugin that allows you to easily create and manage shortcodes for your URLs, simplifying navigation and improving user experience."

★★★★★ (1) Active Installs: 5000+ Tested with: 5.0.20 PHP Version: false
Included Shortcodes:
  • [url_base]
  • [url_template]

URL [url_base] Shortcode

The ‘url_base’ shortcode from the URL-Shortcodes plugin retrieves the base URL of your WordPress website. When implemented, it calls the ‘url_base_function’, which returns the website’s URL. This shortcode is useful for quickly referencing your site’s base URL in posts or pages.

Shortcode: [url_base]

Examples and Usage

Basic example – The shortcode ‘url_base’ returns the base URL of the blog. It does not require any parameters or attributes.

[url_base /]

Advanced examples

Although the ‘url_base’ shortcode does not require any parameters or attributes, we can extend its functionality by adding custom PHP code. This will allow us to use the shortcode with parameters. For example, we can modify the function to accept a ‘path’ parameter. This will append a specific path to the base URL.

The related PHP code would look like this:


function url_base_function($atts) {
    $atts = shortcode_atts(
        array(
            'path' => '',
        ), $atts, 'url_base' );

    return get_bloginfo("url") . $atts['path'];
}
add_shortcode('url_base', 'url_base_function');

Now, we can use the ‘path’ parameter in our shortcode:

[url_base path="/about-us" /]

This will return the base URL of the blog with ‘/about-us’ appended to it.

PHP Function Code

In case you have difficulties debugging what causing issues with [url_base] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('url_base', 'url_base_function');

Shortcode PHP function:

function url_base_function() {
	return get_bloginfo( "url" );
}

Code file location:

url-shortcodes/url-shortcodes/url_short_codes.php

URL [url_template] Shortcode

The ‘url_template’ shortcode is a handy tool, designed to return the URL of the current theme. When implemented, it fetches the root directory of the theme and combines it with the template name. If unsuccessful, it returns an empty string.

Shortcode: [url_template]

Examples and Usage

Basic example – A simple usage of the ‘url_template’ shortcode to retrieve the current theme’s root URL along with the template name.

[url_template /]

Advanced examples

Although the ‘url_template’ shortcode does not take any parameters/atts, it can be used in conjunction with other shortcodes or functions to achieve more complex results. Below are two examples:

1. Using the ‘url_template’ shortcode as a parameter within another shortcode. This example uses the ‘url_template’ shortcode to dynamically generate the URL for the ‘img’ shortcode, which displays an image.

[img src="[url_template]/images/my-image.jpg" /]

2. Combining the ‘url_template’ shortcode with a PHP function in a template file. This example uses the ‘url_template’ shortcode to dynamically generate the URL for the ‘get_header_image()’ function, which retrieves the header image URL.

<?php echo do_shortcode('[url_template]').'/'.get_header_image(); ?>

PHP Function Code

In case you have difficulties debugging what causing issues with [url_template] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('url_template', 'url_template_function');

Shortcode PHP function:

function url_template_function() {
	if( get_theme_root_uri() && get_template() ) {
		return get_theme_root_uri() . "/" . get_template();
	}
	else {
		return "";
	}
}

Code file location:

url-shortcodes/url-shortcodes/url_short_codes.php

Conclusion

Now that you’ve learned how to embed the URL ShortCodes Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

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