Dynamic Text Shortcode

Dynamic text shortcode allows you to insert dynamic text fragments and combine them with static text within one text block / sentence.

Let’s say you wish to add a heading to your post/page, which is dedicated to some real estate property. The text should go like this: “Amazing 2 bedroom apartment in Central London”. However, the values for the number of bedrooms, type of the property and location should be personalized and populated dynamically from the values of post/page custom fields.

First you need to add custom fields “Bedrooms”, “Property Type” and “Location” using TheGem’s Custom Fields or ACF/Toolset fields as described in chapter “Custom Fields”. You need to note the fields name, which will be the used in the dynamic text shortcode. Let’s say we have specified following field names:

  • Bedrooms: _tg_cf_bedrooms
  • Property Type: _tg_cf_property_type
  • Location: _tg_cf_location

Now, in page options of this post/page you can enter the personalized values of these fields:

Good, now you need to start the page builder and choose the “Heading” element to add on this page. To insert the dynamic text values in our text, you need to use following shortcode:

[tg_meta key="FIELD_NAME"]

In our example the sentence should be like this:

Amazing [tg_meta key="_tg_cf_bedrooms"] bedroom [tg_meta key="_tg_cf_property_type"] in [tg_meta key="_tg_cf_location"]

The best part of dynamic text shortcode is to use it in the templates builder -> single post. You can create one template for your post, insert headings and text combining static and dynamic text fragments and apply this template on all relevant posts. In this way each post will display the same design but different personalized text fragments.

Following content elements support the usage of the dynamic text shortcode:

TheGem Elementor

  • Heading, Animated Heading: all text fields
  • Text Editor: TinyMCE editor
  • Accordion:

  • Animated Heading:

  • Button:

  • Call To Action:

  • Infobox: all text fields
  • Pricing Table: all text fields
  • Quickfinders:

  • Quoted Text: all text fields
  • Tabs & Tours:

  • TextBox:

TheGem WPBakery

  • Heading: all text fields
  • Text Block: TinyMCE editor
  • Infotext: all text fields
  • Accordion: section titles
  • Tabs: section titles
  • Tours: section titles
  • Alert Box: buttons text fields
  • Pricing Table: in all nested elements
  • TheGem Button: button text
  • Quoted Text: TinyMCE editor
  • Styled List: TinyMCE editor
  • Table: TinyMCE editor
  • Styled Textbox: TextBox title

Note: for custom fields created with the Toolset plugin you need to prepend “wpcf-” to the field’s name. For example, if your fields’s name is “second_subheader”, so you need to insert [tg_meta key="wpcf-second_subheader"] to display the value of this Toolset custom field.