Field connection shortcodes (Themer)
For row or module settings that have text-based fields, instead of connecting the entire module field, you can alternatively insert the connection as a shortcode. Use a field connection shortcode when you want to use more than one connection in a text field or a combination of field connections and text.
Suppose that besides the using the Post Title in your heading, you also want to add the author's name, with a dash between the two, as shown in this screenshot:
You can tell which connections are eligible to be used as shortcode when you mouse over them in the list and see an Insert button, as shown in the following screenshot.
Click Insert to insert a connection shortcode at the current position of the cursor.
Here's how you'd add Post Title – Author Name, consisting of the shortcodes for two field connections separated by a dash, to a Heading module:
- Open a Heading module for editing in your page or your layout.
- Click the plus sign to the right of the heading field to open the list of connections.
- Mouse over Post Title and click Insert.
You'll see the following shortcode appear in the field:
- Add a dash after the Post Title in the field by typing a space, then
–, then a space again.
- Click the plus sign again, scroll down to Author Name, and click Insert.
The text string in the Heading field is now
[wpbb post:title] – [wpbb post:author_name link="no"]
- Save the Heading module when you're finished editing it.
Here are some examples of field connection shortcodes that get inserted depending on the settings you choose for the connection:
[wpbb post:date format="M j, Y"]
See the article on date formats in the WordPress codex.
[wpbb post:custom_field key="my_field"]
In addition to the standard shortcodes that display text content, you can also specify conditional shortcodes that display content only if the shortcode does or does not return content. Creating a conditional uses the
To check whether a shortcode returns content, use the following
[wpbb-if post:featured_image] Has a featured image. [/wpbb-if]
You can use shortcodes that have settings such as a custom field connection:
[wpbb-if post:custom_field key="my_field"] Has a custom field with the key my_field. [/wpbb-if]
Or, if you're using a field created with the Advanced Custom field plugin, you'd use the attributes from that field. The following code shows an example of inserting an ACF of type
Image only if the field contains an image.
[wpbb-if post:acf type="image" name="corp-photo"] <div class="fl-post-feed-image"> <img src="[wpbb post:acf type='image' name='corp-photo' image_size='thumbnail']"/> </div> [/wpbb-if]
To check whether a shortcode doesn't return content, add the
! symbol before the property, as shown below:
[wpbb-if !post:featured_image] Doesn't have a featured image. [/wpbb-if]
[wpbb-if !post:custom_field key="my_field"] Doesn't have a custom field with the key my_field. [/wpbb-if]