Add Custom Shortcode in any Post Type

Standard

If you need to add custom shortcode in your site then this article is useful to you.

Add below Function in your theme’s function.php.

function get_value($atts) {
$arr=['IMAGE_PATH'=>'http://google.com'];
ob_start();
$output = $arr[$atts['key']];
ob_get_clean();
return $output;
}

add_shortcode('variable', 'get_value');

Usage:-

[variable key="IMAGE_PATH"]

add above line in worpress editor(in your post).

Also refer this link for more detail.
https://codex.wordpress.org/Shortcode_API

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s