Easy Create WordPress Theme Options with Framework

Using the options plugin framework allows us to create a theme options. For those developers wordpress templates, this framework helps us to make the initial setting themes without much coding.

how to use options framework plugin

Quoted from the website http://wptheming.com/options-framework-theme/, The Options Framework Theme has all the code included to build a out a full featured options panel. It’s a bundled version of the Options Framework Plugin for those folks who want to build the options directly into the theme (rather than relying on a plugin).

 How to build wordpress theme options for your own theme? 

1. Download options framework from github.

2. Copy that framework folder at your theme directory.

3. Call options-framework.php class from functions.php (your theme functions) like example below


if ( !function_exists( 'optionsframework_init' ) ) {
define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/_/inc/' );
require_once dirname( __FILE__ ) . '/_/inc/options-framework.php';
}

From the example, we must define options framework directory first and call options-framework.php with require_once

4. Create php file as options.php in the root folder of your theme (Your wordpress theme options will be stored here).

5. Write the following syntax in options.php

<?php
function optionsframework_option_name() {
	$themename = get_option( 'stylesheet' );
	$themename = preg_replace("/\W/", "_", strtolower($themename) );
	$optionsframework_settings = get_option( 'optionsframework' );
	$optionsframework_settings['id'] = $themename;
	update_option( 'optionsframework', $optionsframework_settings );
}
function optionsframework_options() {
	$options_categories = array();
	$options_categories_obj = get_categories();
	foreach ($options_categories_obj as $category) {
		$options_categories[$category->cat_ID] = $category->cat_name;
	}
	$options_tags = array();
	$options_tags_obj = get_tags();
	foreach ( $options_tags_obj as $tag ) {
		$options_tags[$tag->term_id] = $tag->name;
	}
	$options_pages = array();
	$options_pages_obj = get_pages('sort_column=post_parent,menu_order');
	$options_pages[''] = 'Select a page:';
	foreach ($options_pages_obj as $page) {
		$options_pages[$page->ID] = $page->post_title;
	}

	$options = array();

// options will be written below
	$options[] = array(
		'name' => __('License Keys', 'standar'),
		'type' => 'heading');
	$options[] = array(
		'name' => __('License key', 'html5reset'),
		'desc' => __('License key', 'html5reset'),
		'id'   => 'my_licensekey',
		'std'  => '',
		'type' => 'password');
	$options[] = array(
		'name' => __('Secret key', 'html5reset'),
		'desc' => __('Secret key', 'html5reset'),
		'id'   => 'my_secretkey',
		'std'  => '',
		'type' => 'password');
	$options[] = array(
		'name' => __('Google Webmasters', 'html5reset'),
		'desc' => __("Speaking of Google, don't forget to set your site up: <a href='http://google.com/webmasters' target='_blank' rel='nofollow'>http://google.com/webmasters</a>", 'html5reset'),
		'id' => 'meta_google',
		'std' => '',
		'type' => 'text');
// Ads
	$options[] = array(
		'name' => __('Advertisements', 'html5reset'),
		'type' => 'heading');
	$options[] = array(
		'name' => __('Header Ads', 'html5reset'),
		'desc' => __('Header Ads (Use 728 x 90 Banner ads)', 'html5reset'),
		'id' => 'my_ads1',
		'type' => 'textarea');
	$options[] = array(
		'name' => __('Home Ads', 'html5reset'),
		'desc' => __('Home Ads (Use 300 x 250 Banner ads)', 'html5reset'),
		'id' => 'my_ads2',
		'type' => 'upload');
	return $options;
}

Explanation :

  • To create options heading write the following syntax.
$options[] = array(
 'name' => __('Advertisements', 'html5reset'),
 'type' => 'heading');

  • To create options value write the following syntax.

$options[] = array(
		'name' => __('License key', 'html5reset'),
		'desc' => __('License key', 'html5reset'),
		'id'   => 'sgt_licensekey',
		'std'  => '',
		'type' => 'text');

  • From the official website, These are the options currently available.- text
    – textarea
    – checkbox
    – select
    – radio
    – upload (an image uploader)
    – images (use images instead of radio buttons)
    – background (a set of options to define a background)
    – multicheck
    – color (a jquery color picker)
    – typography (a set of options to define typography)
    – editor
    I tried to add a password options and not be a problem.

    'type' => 'password'

example wordpress theme options

 How to call theme options value that we have built 

Use syntax below to call the wordpress options we have built

of_get_option("value_id")

In example :

If you have google site verification options, you can put the source code in header.php as below

echo '<meta name="google-site-verification" content="'.of_get_option("meta_google").'" />'; ?>

Okay, easy right. If you have question or want to provide feedback on my articles, please write comment below. In addition to the Easy Create WordPress Theme Options with Framework article, there are a lot of my articles useful for you, please check here

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

%d bloggers like this: