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://wp247.net.

Set up a copyright notice in a footer widget:

Copyright &copy; <a href=”[wp247_get_option option=’siteurl’]”>[wp247_get_option option=’blogname’]</a>. All rights reserved.

results in:

Copyright &copy; <a href=”http://wp247.net“>WordPress 24x7</a>. All rights reserved.

displays as:

Copyright © WordPress 24x7. All rights reserved.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

 
 

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

Theme by HermesThemes

Copyright © 2017 WordPress 24x7. All Rights Reserved