WPCode Logo

WPCode Documentation

Documentation, Reference Materials, and Tutorials for WPCode

Most Popular

Get free tips and resources right in your inbox, along with 500+ others

Follow Us

Using Shortcode Attributes

WPCode version 2.0.12 added support for using shortcode attributes in your snippets. What this means is that you can now pass data to your snippet when using it as a shortcode.

How are shortcode attributes useful? They make it really easy to reuse a snippet in multiple places when you only need to change a small part of the snippet, making maintenance of snippets a lot easier and less error-prone.

For example, if you own a blog where you write book reviews, you can have a snippet set up for a nice-looking author box that you want to use as a shortcode, with shortcode attributes you can pass the author name and short description to your snippet by simply adding those values as attributes for your shortcode: [author-box name="Jules Verne" bio="French novelist, poet, and playwright"].

Registering Shortcode Attributes

Before you can use shortcode attributes in your snippet you will need to register them. We added this extra step so that you have more control over which attributes are available and also to prevent the shortcode from being abused by users on your site. An attribute added to the shortcode that is not registered in the snippet settings will have no effect on the snippet.

Adding attributes is really easy, all you have to do is make sure you are in Shortcode mode in the Insertion settings box and look for Shortcode Attributes, you will find an input where you can add your shortcode attribute and clicking on the “+ Add Attribute” button will add the attribute to your snippet.