We’ve all been there, hard coded some text in our WordPress sites that exists in a WordPress option and then later changed the WordPress option value but forgot about the hard coded text throughout our website. Then, later discovered the inconsistency and had to go through and find and fix all occurrences of the hard coded text.
I am a big fan of the Shortcode Exec PHP WordPress plugin and have used it some for this type of situation. I would set up a specific shortcode for each type of data I needed. It became apparent that many of these shortcodes were pulling WordPress options data. So, to make life a little easier, I created a WordPress plugin to retrieve options data via a shortcode.
Introducing the WP247 Get Option Shortcode WordPress plugin. This plugin allows you to include WordPress options anywhere shortcodes are accepted.
Syntax
[wp247_get_option option=”desired-option” default=”desired-default” scope=”desired-scope“]
where:
desired-option is the option to be retrieved from the WordPress wp_options table.
Default: none
desired-default is the default value to be returned if the desired option does not exist.
Default: “”
desired-scope indicates which type of option is to be retrieved. scope=”site” will retrieve options using the WordPress get_site_option function. All other values are ignored and the WordPress get_option function will be used to retrieve the desired option value.
Default: “”
Examples
Include the WordPress site URL in some text somewhere:
This is my site’s URL: [wp247_get_option option=”siteurl”].
results in:
This is my site’s URL: http://old.wp247.us.
Set up a copyright notice in a footer widget:
Copyright © <a href=”[wp247_get_option option=’siteurl’]”>[wp247_get_option option=’blogname’]</a>. All rights reserved.
results in:
Copyright © <a href=”http://old.wp247.us“>WordPress 24x7</a>. All rights reserved.
displays as:
Copyright © WordPress 24x7. All rights reserved.