Field Connection Shortcode Syntax
The Field Connection shortcode offers a straightforward way to showcase data from custom fields in your layouts. This reference illustrates the syntax for the field connection shortcode.
To make things even easier, you can generate the shortcode automatically by using an HTML module and the Field Connection Insert function.
Syntaxβ
The Field Connections shortcode syntax varies based on the data type, the location where it is applied, and whether it supports parameters. Below are two examples that demonstrate how the syntax can vary depending on the data's location.
[wpbb post:title]
[wpbb archive:title]
Conditional Shortcodesβ
The Field Connections shortcode syntax supports conditionals, allowing you to display dynamic content based on the evaluation of statements as TRUE
or FALSE
.
[wpbb-if some-field-connection]
If True, show this!
[/wpbb-if]
See the Conditionals article for more information.
Parametersβ
The Field Connection shortcode syntax provides support for a range of parameters, enabling you to perform various actions, such as modifying the output, displaying content based on the field's returned value, or setting a default value.
Modifiersβ
The modifier parameter is available for field connections that have option support. These options grant you the ability to configure the field connection output according to your preferences. After configuring the options, they are incorporated into the shortcode syntax as modifier parameters. The value you selected for each individual option is then utilized as the corresponding value for the modifier parameter.
The two examples below demonstrate how the modifier parameters can differ for each field connection.
Example: Post Date
The post date field connection comes with a parameter namedformat
, which allows you to modify the date format returned using PHPdate()
.Post Date[wpbb post:date format='F Y, J']
Example: Featured Image
The featured image field connection offers parameters likesize
,display
,align
, andlinked
, allowing you to adjust the output accordingly.Featured Image[wpbb post:featured_image size='large' display='tag' align='default' linked='no']
Expressionsβ
Expressions extend the functionality of the conditional field connection shortcode through two parameters: exp
(operator) and value
(comparison value). This allows you to display content based on the value returned by the field.
[wpbb-if some-field-connection exp='<operator>' value='<comparison value>']
Display this text when the value test is True.
[wpbb-else]
Display this text when the value test is False.
[/wpbb-if]
See the Expressions article for more information.
Defaultsβ
Field Connection shortcodes support default modifier parameters that enable the addition of a default value to a Field Connection shortcode. These two default modifiers have slightly different functions, depending on the default value youβre adding.
The parameters default=''
and wpbb_default=''
are incompatible with Conditional shortcodes, as they enforce the statement to be consistently TRUE
.
default=''
β
TheΒ default=''
parameter is optional and specifies a default value that is returned if the field has no value. The default value can include plain text, or HTML markup.
[wpbb post:custom_field key='name' default='John Doe']
Example: Default Featured Image
In this example, the default value is a URL to a default image (default.jpg). If the post has no featured image, the default image is displayed.<img src="[wpbb post:featured_image size='large' display='url' default='https://my-website.com/wp-content/uploads/default.jpg']">
wpbb_default=''
β
The wpbb_default=''
parameter is optional and used instead of default=''
when the default value is sourced from a custom field.
[wpbb post:custom_field key='FIELD_NAME' wpbb_default="wpbb post:custom_field key='FIELD_NAME'"]