Update: This post is crazy old and there are way better options for … options panels now. Like the customizer! Otto can tell you how to leverage the customizer for your theme options. Or, heck, just go ahead and check out the sample code we use all the time.

Problem: You want to create a simple theme options page for your new WordPress theme but all the tutorials and sample theme options pages you’ve seen are way too complex or don’t fit in at all with the existing WordPress look.

Solution: We’ve come up with a simple, sample theme options page you can use for your next theme!

We’ve based this theme options page on the awesome sample plugin options page created by Ozh of Planet Ozh—only now with the bonus Radio and Select options and a Text Area.

Everything is bundled up in a Twenty Ten child theme called A Theme Options Theme—an instant working example—that you can download at the end of this post but here’s how you’d want to use it in your own themes …

How To Use theme-options.php

First, drop theme-options.php in your theme directory and include it in your theme functions.php file like so:

require_once ( get_template_directory() . '/theme-options.php' );

Or, if you’re including the options page with a Child Theme (just like in A Theme Options Theme) like so:

require_once ( get_stylesheet_directory() . '/theme-options.php' );

Then, whenever you need access to one of your new settings, you can do something like the following in any theme template …

<?php $options = get_option('sample_theme_options'); echo $options['sometext']; ?>

Pretty simple, right? While you’re at it, you’ll probably want to use your text editor’s find and replace feature to change “sample” in theme_options.php to the name of your theme. So, for example, if your theme was named Shabadoo you’d go from this …

register_setting( 'theme_options_options', 'theme_options_sample', 'theme_options_validate' );

to something like …

register_setting( 'shabadoo_options', 'shabadoo_theme_options', 'theme_options_validate' );

Of course, Shabadoo is only a suggested theme name. But if you’d like to use it, it’s all yours. Just like theme-options.php is all yours. We hope you can use it to get a quick start on enhancing your themes with a simple options page. Good luck.

Download A Theme Options Theme.

Share this: Twitter

Facebook

More

Email

LinkedIn



Pinterest

Pocket



Print

Reddit



Skype

Telegram



Tumblr

WhatsApp



Like this: Like Loading... Related