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: Sam ZamanSam loves to write on technology & related stuff. Ecommerce, mobile and internet marketing equally drive her interest. Likes gardening and experimenting with new recipes. An avid reader and absolutely mad @bout donuts :)

Leave a Comment