All Collections
Dynamic Shortcodes
What are Keyargs in Dynamic Shortcodes
What are Keyargs in Dynamic Shortcodes
Updated over a week ago

Understanding Keyargs in Dynamic Shortcodes

Dynamic Shortcodes provide an easy way to pass additional data and settings to the shortcode by using Keyargs.

What is Keyargs Syntax?

Keyargs is an easy syntax that allows you to pass additional data and settings to Dynamic Shortcodes. One Keyarg has a key and a value associated to it. The key is a simple text identifier (for example, id or format) and the value can be virtually anything, depending on the requirements. The key and value are connected with an equal sign.

An example of a Keyarg is:

id=42

which associates the number 42 with the key id.

Usage of to Keyargs in Dynamic Shortcodes

Keyargs must be specified in a keyarg section, a keyarg section is a list of keyarg declarations separated by spaces. A keyarg section is introduced by the @ symbol.

All in all, if you have a shortcode like

{query:posts}

we can add Keyargs like this:

{query:posts@tag=food}

If you want to add more than one, you can do

{query:posts@tag=food post-status=publish}

Omitting the Value

As a special case, a keyarg can omit the value. These are used to pass simple on/off flags to the Dynamic Shortcodes. A truth/on value is implied. For example, in

{acf:field@format}

you are telling the ACF Dynamic Shortcodes field to format the field according to the ACF Field settings. You could use

{acf:field@format=1}

but that is unnecessary.

Did this answer your question?