Dynamic Content Variables (DCV)

Note: In order to use this feature on a site, two plugins must be enabled: “Global Variables” and “Custom Fields”

The Dynamic Variables feature allows you to add a list of site and global-level variables that can be auto-populated into content across the site when inserted into a page or post. 

For v1 of the feature, the variables would be added manually to the Network settings and site specific variables, can be added on a site by site basis. 

In future versions of the feature, we will look to integrate this plugin with Central Park so that variables created in there, can be automatically pulled into WordPress to remove the need to add these manually. 

All variables can be inserted anywhere inside a page or post, within any block. There are no limits to how many variables can be created or inserted into a page/post. 

Jump to:

Network Variables:

Variables added at a network-level will apply across all sites added to the network. 

Site-level Variables:

Site-level variables will only apply to the site they are added on and no others in the network.

How to Use:

Network-level Variables

Network-level Variable Creation

To create a Network-level Variable, you must be on the ‘base’ site. To find out which site is the ‘base’ site:

  1. Go to the WP Dashboard
  2. Hover over My Sites
  3. Hover over Network Admin and click Sites 
  4. At the top of the list, you’ll see a site which has Main written next to it 
  5. This is the Base site 

Then, if you go to the Dashboard of the Base site, and go to Settings on the left-hand side, you’ll see a new option for Network Global Variables. In this screen, you can set up all of the variables which will be usable across all of the sites on the Network.

To add a Variable:

  1.  Click Add Variable
  1. Open up the accordion for the Variable
  2. Give the Variable a Key e.g. this-is-the-key
  3. Give the Variable a Value e.g. This Is The Value
  4. Remember to hit Save in the top right of the screen  
  1. This Variable is now usable across all of the sites on the Network

To remove a Variable

  1. Open the accordion for the Variable you want to remove
  2. Click Remove Variable button 
  1. You’ll see a prompt to ask you to confirm you want to remove the variable
  2. Remember to hit Save

Global-level Variables

Global-level Variable Creation

To create a Global-level Variable, you must be on the Dashboard of the site you want to create the variable for. Once you’re on that Dashboard:

  1. Go to Settings > Global Variables 
  2. On this page, at the top, you’ll have a list of all of the Network-level variables that are available and any site specific variables underneath

To add a new Variable:

  1. Click the Add Variable button
  2. Open up the accordion
  3. Give the Variable a Key e.g. the-key
  4. Give the Variable a Value e.g. Value 
  5. Remember to hit Save in the top right of the screen 
  6. This Variable is now usable across all this one site 

To remove a Variable:

  1. Open the accordion for the Variable you want to remove
  2. Click Remove Variable button 
  3. You’ll see a prompt to ask you to confirm you want to remove the variable
  4. Remember to hit Save

Inserting a Variable 

To use a Network or Global Variable, there is a new icon in the toolbar at the top of the editor (next to the Settings icon).

You’ll start on the Network tab which shows all of the Network-level variables available.

Next to that is the Site tab which shows all of the Site Global Variables. 

Then a Usage tab which shows where any variables have been used on the Page/Post and which Block they’re used in.

Inserting a Variable into Content

To place a Variable within some content, you should first decide whether you are wanting to insert a Network or Site-level Variable. Once chosen, make sure you are on the correct tab to reflect that (e.g. Network or Site).

Find the Variable you want to insert from the list, or search for the Variable using the Search by Key functionality. Each Variable will show you the Value & it’s Key underneath, in blue; which reflects what will be outputted on the front-end.

To use the Variable, click the Copy icon on the right side of the Variable. This will copy the Key to your clipboard. You can then paste the Key into any piece of content or within any Gutenberg Block.

Click Update on your Page/Post and view the page on the front-end. You’ll see the Key is outputting the Value of the Variable.

How Duplicates Variables are Handled

Duplicate Variables

How we handle duplicate variables 

If a Variable has been added to the Network variables, and the same Variable is then added at a Site-level, this will not cause any issues as all Network-level Variables are prefixed with ‘gv-’ which is only used for visual purposes so that you can see that it is a Network-level Variable. 

Network-level Variables that have the same Key as a Site-level Variable, act as a fallback if this Variable is ever deleted. Meaning, if you are using a Site-level Variable e.g. Price on your site with a Value of $50, but you also have a Network-level Variable for Price with a Value of $100; if your Site-level Variable is ever deleted, it will fallback to the Network-level Variable. This means there will always be a Value outputted on the front-end and there would never be a risk of a Key e.g. %%this-price-50%% rendered in the front-end of the site. 

If you then wanted the Price Variable to be site-specific, you can just add a new Site-level Variable to the site you want it to appear on and it will replace that Value

The Site-level Variables would always take precedence over the Network-level Variables if the same Value is used. 

Overrides

If you want to use a Network-level Variable, regardless of if there is a Site-level Variable with the same Value, you can do this by editing the Key within the content and adding ‘gv-’ to the beginning of of the Key. E.g. changing %%price%% to %%gv-price%%. This acts as an override and means this will always use the Network-level Variable and not the Site-level Variable. 

Variables Usage

Variables Usage – Page Level

What is the ‘Usage’ tab? 

The Usage tab within the Global Variables sidebar, is there to aid a user who is trying to see what Variables have been used on a Page/Post and easily taken them to this Variable. 

Clicking the Usage tab will show you a list of all Variables that are being used on that Page/Post. Just like the other two tabs, it will show you the Variables Value & Key underneath, in blue. 

You also have the ability to search for a Variable, if the list is extensive. The search is consistent across all 3 tabs, so if you search for a Variable in the Network tab, it will also perform the search on the other 2 tabs too (Site Usage) to save you from having to perform the search multiple times. 

Clicking on one of the Variables will take you to the Block that the Variable is used in (like a page anchor). 

Variables Usage – Site-level

Where is the Variable being used?

If you want to see where a Variable is being used across a Site, you can do this by:

  1. Go to the Dashboard of your Site
  2. Go to Settings Global Variables
  3. Open the accordion for the Variable to want to see the usage for 
  4. Underneath the Key field you will see a message saying “Variable used on 1 page
    • The number of pages will change to reflect how many pages the Variable is being used on 

This works in real time, so if you add a Variable to another Page on the site, and hit the Refresh icon, it will pull in the new Page using the Variable 

  1. Click the 1 Page link, this will take you to a filtered list of Pages where the Variable is being used 
  2. There is also a new Column in the all Pages/Posts screen, called Variables, which lists the Key of any Variables used on that Page/Post
  1. If you go back to Settings Global Variables and open the accordion under the Network Global Variables section, it will show you where each Variable is being used as a Fallback

Variable Validation

How we validate Variables

Within a Page/Post, if a user tries to type in a Variable that does not exist in either the Network or Site-level Variables list, an error will be shown at the top of the page reading “Detected undefined variable(s): name of Variable:

If there is more than one unrecognised Variable, the error message above will show the names of each undefined Variable, separated by a comma. When this error is present, it will not be possible to Update or Publish the Page/Post. This will prevent any unrecognised Variable Keys being outputted on the front-end as text. 

Audit Trail

Variable Audit Trail

Where are Revisions stored?

Whenever a Variable is createdmodified or deleted, this information will be stored as an audit within the wp-stream plugin. 

The messaging will read as follows:

  • Deleted:  “%s” variable has been deleted.
  • ModifiedThe “%s” variable has been modified, the new value is “%s” and the previous value was “%s”.
  • Created:  A new variable has been created with a key of “%s” and a value of “%s”.

Best Practices

Variable Best Practices

URLs

  • When setting up a Network or Site level Variable as a URL, you don’t need to include the https:// protocol
    • This is because, when used in links, WordPress will add the protocol for you, meaning you would end up with the protocol twice and the link won’t work
    • If you want to use a URL Variable as a link within some text, all you need to do is copy & paste the Variable Key e.g. %%site-url%%, into the link field and hit enter 
    • If you want to show the URL as text and show the protocol, you would paste the Variable Key e.g. %%site-url%%, and type https:// in front of the Variable Key e.g. https://%%site-url%%

Email Addresses

  • When using an Email Variable, you would copy & paste the Variable Key as normal, paste it into your content, highlight the text and click the link icon
    • You must then make sure you add mailto: at the start of the link before pasting in the variable

Phone Numbers

  • When using an Phone Variable, you would copy & paste the Variable Key as normal, paste it into your content, highlight the text and click the link icon
    • You must then make sure you add tel: at the start of the link before pasting in the variable

Buttons

You can also use URLs within Buttons by simply pasting the Variable into the Button link field.

Demo videos

We have recorded some demo videos to provide some more insight and examples of the feature in action, these can be viewed below: