We are reader-supported. When you buy through links on our site, we may earn an affiliate commission. Learn more.

Quick Guide To Wordpress Shortcodes

Shortcodes Introduction

The basic purpose of using a shortcode is to replace the placeholder with your very own custom snippet of HTML. This powerful function allows you to customise the layout of posts, insert different types of buttons or media and even snippets of HTML. It doesn’t take an experienced wordpress developer to implement shortcodes, with just a few simple shortcodes you’ll soon be on your way.

Writing The Shortcode Function

A basic wordpress shortcode consists of a simple function in which we insert inside of the “Functions.PHP” file. The function can be inserted anywhere at the bottom of the functions file, this is probably best practice as the function file more than likely contains a mountain of PHP code anyway.

On my tutorial blogs i have a number of shortcodes one of which is a simple little text box for containing tips. On Code-Snippet it looks like this.

Important Tip

This is my shortcode box for writing tips.

The shortcode function looks like this

[code type=php]
function tipsbox() {
return ‘

Important Tip

This is my shortcode box for writing tips.

‘;
}

add_shortcode(‘photoshoptip’, ‘tipsbox’);
[/code]

To display this in shortcode, in our wordpress post we would simply add the following snippet.

[code type=php]
[photoshoptip]
[/code]

When viewing the post live on the website the shortcode snippet will be replaced with the HTML code inside of our function.

Conclusion

Wordpress shortcodes can be used in many many ways, this tutorial is just one simple demonstration of a shortcode. In a later tutorial we’ll be talking about passing arguments to functions. If you can;t wait that long maybe give the wordpress Shortcode API Codex a try.


Author: Tom ClaytonTom loves to write on technology, e-commerce & internet marketing. Tom has been a full-time internet marketer for two decades now, earning millions of dollars while living life on his own terms. Along the way, he’s also coached thousands of other people to success.
css.php