Select Page

A lot of plugins have shortcodes that can be used inside a post or a page’s content. These shortcodes help add new functionality to your WordPress website. If you want to call a shortcode inside your template, there’s a very easy way to do it.

All you have to do is call the do_shortcode function:

<?php
echo do_shortcode("[shortcode_name]");

The above snippet will output the results of calling the shortcode.

But what if you want to pass some arguments to the shortcode? You can easily do that too:

echo do_shortcode("[shortcode_name arg1='test' another_argument='value']");

You can pass any number of arguments to the shortcode just the way you would inside a page’s content.

You can also use the closing syntax of shortcodes to pass content inside the shortcode like this:

echo do_shortcode("[shortcode_name]Content Goes Here![/shortcode_name]");

If you want to check if the required plugin is active or not that this shortcode belongs to, you can use this snippet:

$plugins = get_option('active_plugins'); // Get a list of all active plugins.

// The main PHP file that of the required plugin.
// A plugin's main file is the same name as the name of the plugin's folder.
$required_plugin = 'required_plugin_name/required_plugin_name.php';

if ( in_array( $required_plugin , $plugins ) ) {
	$required_plugin_active = true;
}else{
	$required_plugin_active = false;
}