Using The Options

djevrek edited this page Mar 28, 2013 · 6 revisions

Getting and Showing your theme options.

Rendering the Redux Options out on the front end is fairly simple, though a basic working knowledge of WordPress and PHP is a prerequisite for using this framework. Below are a few examples of how you could use your saved options, and assumes you have already at least setup the default options panel in the admin.

Retrieve The Options From the Database

First we need to retrieve the options values that have been saved to the database. This must be done in any script where we plan to use our options. To do this we should use the folowing which will retrieve an associative array of all the theme options and store them. This uses the built in WordPress function 'get_option()' :

$options = get_option('opt_name');

note that the opt_name should have been set near the top of your options.php file when creating the settings. (around line 134 where you'll find $args['opt_name'] = '';).

Use The Options

next we can use the options in the following ways. Note that opt_ID below refers to the ID you set for the field.

Simple echo :

echo $options['opt_ID'];

for a checkbox :

if ( isset($options['opt_ID'] ) ) {
    // do stuff if the checkbox is set

for an image upload :

<img src="<?php echo $options['opt_ID']; ?>" />