Posted in WordPress

Using WordPress shortcode

Using WordPress shortcode Posted on December 20, 2015Leave a comment

WordPress shortcode is a special tag that allow you to do various things with little effort. It helps you to create functions and use them within your  post content.

A shortcode might look like these:

  • [shortcode_name]
  • [shortcode_name param1='value1' param2='value2']
  • [shortcode_name] content [/shortcode_name]

To create a shortcode, you have to use this line:

Callback function accepts there parameters:

  • $args: an associative array of attributes, or an empty string if no attributes are given.
  • $content: the enclosed content (if the shortcode is used in its enclosing form).
  • $tag: the shortcode tag, useful for shared callback functions.

Here are simple examples to create and use shortcode.

Shortcode with no parameters.

To use this shortcode, just put [hello_world] into your post content.


Shortcode with parameters.

Usage: [hello_parameters name='Duc']Nothing to say![/hello_parameters]



Shortcode is only used in post content but in some cases, you want to use it in php file, here is a solution:

That’s all about using WordPress shortcode! I hope you like it, thanks for your reading!




Leave a Reply

Your email address will not be published. Required fields are marked *