Shortcode Tutorial – Types of Shortcodes

Creating shortcodes in WordPress is very simple. But before that, we should know the types of shortcodes in wordpress so that we can create the correct shortcode to make it working.

In WordPress shortcode are of 3 types:

  • Self-Closed Shortcodes
  • Shortcodes With Attributes/Parameters
  • Enclosed Shortcodes

Also we can create custom shortcodes according to our need.

Self-Closed Shortcodes

Self-Closing shortcodes of wordpress are the basic form of shortcodes. This type of shortcodes doesn’t have any end tag but they can also accept parameter values and they close automatically. It contains the shortcode’s name only.

Syntax

[shortcode_name]

Examples

[audio], [video], ...

Enclosed Shortcodes

Enclosed Shortcodes, is a type of wordpress shortcodes that has a start tag and an end tag, just like an HTML tag. These shortcodes allow us to embed content within shortcodes. Also we can pass values into it.

Syntax

[shortcode_name] Content to be displayed [/shortcode_name]

Example

[caption] <image> Caption [/caption]

[embed] Your Content [/embed]

Shortcodes with Multiple Parameters

This is not exactly a type of wordpress shortcode but a shortcode with attributes or values. We can pass parameter values to self-closed shortcodes and enclosed shortcodes.

Syntax

[shortcode_name name="shortcode_name" attribute1="value1" attribute2="value2"]

Example

[recent-posts posts="5"]

[recent-posts posts="5"]This is the list heading[/recent-posts]

In wordpress we have default available shortcodes. We will know about all in detail in next tutorial. Also we can create custom shortcode either self-closed or enclosed shortcodes.

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more