Description
WST Site Variables lets you register information that appears all over your site, such as your phone number, address, and company name, on a single screen, and display it with shortcodes or template functions.
When you change a value, every place that displays it changes at once. If your phone number changes, there is no need to hunt down and edit the header, the footer, and the contact page one by one.
Register variables
On the “Site Variables” screen in the admin, register each piece of information as one row. A variable has a label (its name in the list), a key (the name used to display it), a value, and a type.
Six variables are ready from the start: company or store name, phone number, fax number, email address, postal code, and address. Click “Edit”, enter a value, and click “Save” to start using them. For anything else, create a variable with “Add new variable”.
Display in posts and pages
Copy the shortcode shown on each row and paste it into your content. For the phone number (key tel), it is [wst_site_variables key="tel"]. It also works in the middle of a sentence, such as Call us at [wst_site_variables key="tel"]. Nothing is displayed when the key does not exist or the value is empty.
Phone, email, and URL variables become links when you add link="true", for example [wst_site_variables key="tel" link="true"]. A phone number can then be tapped to call, and an email address opens the mail app. Text variables show only the text, even with link="true".
Display in themes
To display the phone number in a PHP template, write <?php wst_site_variables_echo( 'tel' ); ?>. This function escapes the value and outputs it. Line breaks in multi-line text become <br>.
To make the phone number a link, pass 'href' as the second argument for the link URL only. For example, if the displayed number is 03-1234-5678, the link URL is tel:0312345678.
<a href="<?php wst_site_variables_echo( 'tel', 'href' ); ?>"><?php wst_site_variables_echo( 'tel' ); ?></a>
To use a value in a variable, get it with wst_site_variables_get(). It returns the value as stored, without escaping (multi-line text keeps its line breaks). Escape it for wherever you output it. For example, pass the company name through esc_attr() to use it as the alt text of a logo image.
<img src="logo.png" alt="<?php echo esc_attr( wst_site_variables_get( 'company_name' ) ); ?>">
wst_site_variables_get( 'tel', 'href' ) returns only the link URL. Use `esc_url()` when you output it in a link. Link URLs are available for the phone, email, and URL types.
Editing and reordering
- Variables created with “Add new variable” are added to the top of the list.
- Keys can contain lowercase letters (a-z), numbers, hyphens (-), and underscores (_), up to 64 characters.
- Keys can be changed later. When you change a key, update the shortcodes and templates that use it as well.
- Use the field above the list to filter variables by label, key, or value.
- To display an address or similar text on several lines, choose the “Multi-line text” type. Press Enter for a new line and Ctrl+Enter (Command+Enter on Mac) to save.
- To move a variable, drag the handle at the left end of its row. With the keyboard, focus the handle and press the up or down arrow key. The order is saved automatically. Finish filtering or editing before reordering.
- A deleted variable can be put back in its original position with “Undo” until you reload the page. It cannot be restored if another variable with the same key has been created.
Backup and migration
Open “Backup” below the list and click “Download JSON” to export all saved variables in list order.
To restore them or move them to another site, use a JSON file exported by this plugin (2 MB or smaller). Choose the file and an import mode.
- Merge: Variables with the same key keep their position and get the new label, value, and type. New keys are added to the end of the list.
- Replace all: The whole list is replaced with the contents and order of the file. Variables not in the file are removed.
Click “Preview” to see a table of the variables that will be new, updated, unchanged, or removed. If even one variable in the file is invalid, its number is shown and nothing is imported. After checking, click “Import” to save.
An import cannot be reversed with “Undo”. Export your current variables before importing, so you can return to them.
Screenshots



Installation
- In the WordPress admin, go to Plugins, install “WST Site Variables”, and activate it.
- Open “Site Variables” in the admin menu.
FAQ
-
Are any variables available from the start?
-
Yes, six: company or store name, phone number, fax number, email address, postal code, and address. The company or store name starts as your WordPress site title; the others are empty. You can delete the ones you do not use.
-
What kind of values can I register?
-
Text, multi-line text, phone numbers, email addresses, and URLs. HTML tags cannot be used; they are removed.
Register only information that may be public on your site. Anyone who can write posts can display the values with a shortcode, so do not register passwords or API keys.
-
Are values included in automatically generated excerpts?
-
Yes. When a post has no manual excerpt, WordPress builds one from the content, and the shortcodes in the content are replaced with their values there too.
However, text inside a “Shortcode” block is not included, because WordPress removes the whole block from excerpts. To show the value in excerpts too, write the shortcode in a paragraph.
-
I changed a value, but the site still shows the old one
-
If you use page caching, the old value may appear until the cache is cleared. Clear the cache.
-
Can users other than administrators edit variables?
-
Yes. By default, opening the screen and editing variables requires the
manage_optionscapability. To allow users with theedit_pagescapability as well, use this filter:add_filter( 'wst_site_variables_capability', function () { return 'edit_pages'; } ); -
What happens to my variables when I delete the plugin?
-
All registered variables are deleted with the plugin. To keep your data, download the JSON before deleting the plugin.
Reviews
There are no reviews for this plugin.
Contributors & Developers
“WST Site Variables” is open source software. The following people have contributed to this plugin.
ContributorsTranslate “WST Site Variables” into your language.
Interested in development?
Browse the code, check out the SVN repository, or subscribe to the development log by RSS.
Changelog
1.0.0
- Initial release.