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).
This project was released long before the Customizer was a part of WordPress. The Customizer is now the recommended way to add theme options and you can read more about it here.
Available Options
- 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
Instructions
Copy the “inc” directory, options.php, and the code snippet in functions.php from the “Options Framework Theme” into the theme of your choice. Hack away. You can also watch the video above to see how it is done.
When to Use Theme Version vs. Plugin Version
The code is 99% the same between the plugin and theme version. If you can do what you need with the plugin version, I think that’s the best route. If you find that you need to make significant modifications that aren’t possible with the plugin, go ahead and use the theme version.
Change the Menu Location
It’s highly recommended that you leave theme options under the “Appearance” menu where users expect them.
But, if you do decide to change the menu location it will break the media uploader. This is because the media uploader scripts are enqueued on $of_page= ‘appearance_page_options-framework’ in options-medialibrary-uploader.php. If you change the name or location of the menu, you’ll need to update the hook to be accurate, e.g. $of_page= ‘toplevel_page_options-framework’ and those scripts will load properly again.
Sanitization Filters
If you’re interested in how the options data is verified, or if you’re wondering why your script and embed tags are stripped out in the Options Framework, read this post.
Can I Use This Code in Commercial Themes
Yes! This code is 100% GPL. Please read the included license for more details.
Development Version on GitHub
The development version of the Options Framework Theme is available on GitHub.
Additional Tutorials
- Options Framework + Theme Customizer
- Options Framework Sidebar
- Loading Additional Stylesheets from an Options Panel
- Loading Google Fonts from Theme Options
- Color Palettes with the Options Framework
- Options Framework: Sanitization Filters
The demo themes associated with these tutorials are also available on GitHub.
Just found this and wanted to say, this is just sexy. I’m loving the ease this brings to creating theme options. It literally makes my day; possibly my entire week. Grazie milla!
Grazie mille !
It doesn’t appear that the upload field works in 3.3.1. When I click “Save”, the image disappears. Please advise.
In the HTML of the uploader, I noticed the name was wonky. It was showing as “slideshow_image1” instead of “optionsframework[slideshow_image1]”.
In optionsframework_medialibrary_uploader, I replaced the $option_name = $optionsframework_settings[‘id’]; line with the same check you do in optionsframework_fields():
if (isset($optionsframework_settings[‘id’])) {
$option_name = $optionsframework_settings[‘id’];
}
else {
$option_name = ‘optionsframework’;
};
It is a hack, but it works. I don’t know why this didn’t effect me before.
Do you mind clarifying that? I can’t get it to work–what file did you edit? Thanks!
Alan
Do y’all have the option name set in options.php?
Having problems with media uploader, just getting a white screen in the thickbox.
Moved the options to a top level menu, made the changes as above in the medialibrary-uploader and options-framwork files. Reset browser, no plugins active.
The only other change I made was to rename “Theme Options”. Could this be the problem? Any help on where to debug would be much appreciated.
This is WP version 3.3.1. Still nothing but a blank white screen in the thickbox.
I finally found the problem. I have a custom posttype and was using the add_action (‘admin_head’, “my_icons”) function to add a 32×32 icon. Every time I add that in, the media uploader breaks everywhere.
Extremely strange, and I’ve opened it up for discussion on wordpress.org.
So solved, definitely not the framework :-)
If anyone else runs into this, make sure you aren’t adding 32×32 icons using that add_action method.
Out of curiosity, is there a way to get the attachment ID from a file uploaded, so I can use the thumbnail sizes? (or just pass a thumb size?)
See: https://github.com/devinsays/options-framework-plugin/issues/65
Hi,
Thanks for this plugin/theme! I was actually surprised there’s not something like this built-in into WordPress :)
I was curious though, why didn’t you merge the importer/exporter code? It’s pretty useful, and seems to be mostly well-coded?
Cheers,
Julien
I’m trying to keep the codebase as slim and maintainable as possible. If it is not something that I think 80% of users/developers will use- I’m a bit wary of adding it in. See the WordPress philosophy under “Clean, Lean and Mean”: http://wordpress.org/about/philosophy/.
A couple people have asked about an export function, but it hasn’t been highly requested. What is your use case, if I might ask?
Hi Devin,
I’m building a theme that’s very versatile and has a fairly high number of options (though I’m trying to abstract some of them from the end-user as much as I can).
I’m also deploying a dozen of installs as demo and staging sites for the theme (think demo1.example.com, demo2.example.com, etc.) and want to automate that as much as I can. I’m looking into the new WP CLI too, but exporting/importing theme settings seem more straightforward from the theme itself.
I think it makes sense for the end-user as well: you can import settings from a demo site and then just change what you need to change, etc.
More generally than this precise feature, I think it would be cool to have more extensibility capabilities built in the Framework (so that people can distribute packaged “plugins” to your framework, so to speak). I will be suggesting a few things like this on Github in the next couple of days, I hope you’ll like them! (for instance, I would like to be able to configure — not extend — some options in `options.custom.js`).
Thanks for your terrific work on this framework,
Julien
Great. Look forward to comments on GitHub. For multiple installs you might want to look into something like this: http://www.kathyisawesome.com/421/customizing-wordpress-install/
It think it would be helpful to do a complete re-write of the plugin into object oriented PHP so that it could easily be extended- but am not quite ready to devote the energy to this yet.
Amazing theme/framework. Thanks so much Devin!
Hi,
is possible to add a on/off button? With this button i should be able to show or hide individual options in options panel.
Yes. See the “show hidden” option in Options Check. It would be very similar.
WP (3.3) debugger throws “Notice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or init hooks…blah, blah” error. Any idea how to get rid of it? …or is there any more convenient method to enqueue required scripts?
Thanks a ton for all of your efforts Devin!!!
This was updated. You should no longer get the wp_enqueue_script notices.
Hi Devin,
Is it possible to have a 2nd instance of the options framework to capture different theme options. I don’t want this to be additional tabs, but a separate “page” with different tabs.
Hi Devin,
Is it possible to pass any additional variables to the textarea option? In particular, I need to default the rows and columns larger. Is this possible?
If you’re using the theme version, you can edit it directly. You can also pass a parameter in the option for columns: “options” => array(‘cols’=>’100’), but it looks like the option for columns needs to be added too.
Thanks Devin, I see it. In admin-interface “rows” is hardcoded at the moment, but I think I know how to update this. Will you be adding this to a future version?
Columns has been updated in the framework so you can override.
I think the fully featured media library is not a good choice for uploads. Something much simpler, that just allows the user to upload an image would be a better choice, in my opinion. I’m trying to implement something like that.
If anyone has some suggestions, let me know!
You can look at the very early commits on this project. It originally used an ajax uploader- but I switched to more closely match the WordPress interface.
Thanks for the response, Devin!
Actually, I think there’s a problem with the media uploader WP 3.3.1. The function optionsframework_mlu_js_popup () is not tweaking the media uploader thickbox, removing the gallery settings and changing other stuff.
Check it out!
Would you be able to give me a more detailed bug report on it: https://github.com/devinsays/options-framework-theme/issues/23
Just wanted to say this is ridiculously helpful. Thanks so much to everyone involved in putting it together, helped me out no end!
Hi,
I want to put value of a colorpicker to css for example like this
body { background: ; }
Is it possible?
If you want an example of something like that, you can download my Portfolio Press theme: http://wordpress.org/extend/themes/portfolio-press
Using the image uploader, what is the best way to handle image resizing on upload? Say you had a slider and used this to upload images. Obviously I could just use CSS to declare the size, but is there a way to have WordPress resize/crop the images (like how you can define sizes of thumbnails and how you want them to be cropped). Thanks!
Look at: https://github.com/devinsays/options-framework-plugin/issues/65
Great job, thank you very much. This is going to save me so much development time.
Hey Devin, when I take the two options to create a hidden text field from options.php in the demo version of the theme, and drop them into the options.php of my theme, they only work if I keep the same IDs as you have. Does that make sense?
What ties them together so that I can give them IDs more relevant to my theme?
Thanks
Look in functions.php for “Options Check”. You’ll see that there is custom jQuery code there that makes that functionality happen. You’ll need to edit the div ids in that code if you want to change the option ids.
Nice one, cheers.
Hi, is there an option to add some specific div to one of the tabs?
already echoed a div on options.php but is displayed on every tab.
first of all, great script. i’m planning to use it in my future projects soon. just a siple question Devin, how do I disable the sanitizing of the values? apparently i still need the html tags on simple text inputs.
Since you’re using the theme version, you can edit the sanitization filter directly in options-sanitize.php. I also wrote a little post about it: https://wptheming.com/2011/05/options-framework-0-6/
Great stuff here, for the life me I cannot get a thumbnail from an uploaded image though. This seems to exactly what I want :
http://wordpress.stackexchange.com/questions/35055/resize-image-on-the-fly-custom-field-theme-option
And so here is my code:
get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE guid = '$bio_image'" ) );
$theID = $thepost->ID;
echo wp_get_attachment_image( $theID, 'thumbnail' ); ?>
Nothing comes back. Have tried in various places in my theme, no luck, I can’t work it out.
Hey Devin,
I really love the framework. Extremely good job.
I got one question:
Is it possible somehow that a set of options will appear only when a specific checkbox is ‘checked’?
Thanks in advance,
Zuri
Yes. There’s already an example of that in the options.
I guess I have an older version of the framework with the old UI. It’s been used in a theme I bought a while ago.
Is this function available in the older version?
If not, anyway to update the version without breaking it?
Thanks in advance
Never mind I upgraded successfully :)
A different question though… any plans to implement a configuration backup/restore feature? The one done in https://github.com/vauvarin/options-framework-theme has a lot of bugs and although the backup restore works, other stuff don’t.
Thanks!
Another question if I may.
Is it possible somehow to replace the uploader from WP media library to the simpler one used in previous version?
Thanks
You’re welcome to make a fork and revert to the older version. Eventually WordPress will tackle media and the UI will be better- but for now I am planning to keep the current interface.
Hi,
First of all: thanks for the amazing framework!
I have a small question: I would like to put the options.php file inside the admin folder. Is this possible? Because I see in options-framework.php you’ll have to change the form action path.
Yes. Just change the include filepath for options.php around line 77.
Hey Devin –
Is there a way to link directly to a specific tab view from a different page in the admin?
Not how it is currently coded. You could add it as a feature request: https://github.com/devinsays/options-framework-theme/issues
Hi Devin,
I’m trying to add some kind of on-the-background options, that have to be set when certain options are updated, but are not shown between the options menu. Is there an easy way to do this? Maybe a “do-not-display” type?
Thanks for this amazing framework.
thanks for your time and effort and for making this available to us! theme options always caused a huge nightmare in the past… rock on! :)
Hi Devin,
I really love the framework. Amazing job!
I was playing with the “optionsframework_custom_scripts” function to hide and show option fields. Thanks to your example I’ve got it working on my checkboxes, but is it possible to attach it to dropdown menu’s (select)?
I already have this code:
jQuery('slider_effect').change(function() {
jQuery('#section-slider_fadespeed').fadeToggle(400);
});
if jQuery('slider_effect').val("Fade")) {
jQuery('#section-slider_fadespeed').show();
}
What I want to achieve is that when the user selects the option “Fade” in the dropdown, the input field “Fadespeed” displays. At this moment, the correct input field appears and saves, but when the options page refreshes, all the fields are displayed, even when “Fade” isn’t selected.
Thanks in advance.
You’d need to detect select’s value on each page load, and then display or hide section-slider_fadespeed depending on it’s state.
Thanks!
I’ve fixed it with the following code:
if (jQuery('#slider_effect option:selected').val() == "slide") {
jQuery('#section-slider_fadespeed').hide();
}
It works perfect!
Hey Devin,
I got an issue when trying to use the ‘select’ type when the options are a list of fonts in a directory.
The problem is that the “value” in each “option” is the array number (1,2,3,4,5,etc), and the actual font file name isn’t passed. So when I try to dynamically use the selected font, it returns the number, instead of the wished font name.
Any idea how I can solve this? Here’s the code: http://dl.dropbox.com/u/1226755/fonts.txt
Any assistance would be appreciated,
Thanks
You should be able to define the key to whatever you want. There’s no reason it needs to be 1,2,3,4,5. See $test_array in the Options Check theme (in options.php).
Yes I know I can manually define the keys, but in my case the $key needs to be the JS filenames, which is dynamic according to the files in the given directory.
Is it possible the pass the $value not as the value tag defined in each option tag, but rather the option itself?
Currently it’s working like this:
[option value=”1″]file1.js[/option]
Is it possible the it will work like this?
[option]file1.js[/option]
Thanks
Yep, that’s exactly what I meant. Look at $test_array to see how both keys and values are defined.
I did, and therefor I tried to change the defenition in the options-interface.php file. I tried to remove the “value” tag from the output but then the option select just isn’t saved.
I even tried to change $val == $key to $val == $option
and value=”‘ . esc_attr( $key ) . ‘” to value=”‘ . esc_attr( $option ) . ‘”, but even here, the option selected isn’t saved for some reason.
OK I figured it out :)
Thanks for points the stuff to me :)
Hi,
I realize I posted in the wrong section since I’m using the options framework theme. When using the code below, a text editor does appear in the options panel. However, whatever I type in it is not saved. I’m probably doing something wrong but I can’t figure out what exactly.
$options[] = array( "name" => "Default Text Editor",
"desc" => "Here is the description.",
"id" => "example_editor",
"type" => "editor");
Thanks !
I haven’t moved that code into the theme version yet. It’s still being tested. In the plugin version (with Options Check), it is working for me. Is it not working for you?
// Editor
function of_sanitize_editor( $input ) {
global $allowedposttags;
$output = wp_kses( $input, $allowedposttags );
return $output;
}
add_filter( 'of_sanitize_editor', 'of_sanitize_editor' );
Add this to options-sanitize.php maybe helps …
@Devin : it is working in the plugin version, indeed.
@Oskar : thanks a lot, it seems to be working !
I’m trying to create a term selector for a custom taxonomy, but it only pulls in one term. Here is what I’ve got:
// Pull all the product categories into an array
$options_productcategories = array();
$options_productcategories_obj = get_terms('productcat');
foreach ($options_productcategories_obj as $procategory) {
$options_productcategories[$procategory->term_ID] = $procategory->name;
}
Can anybody help?
So, this works for me:
// Pull all the categories into an array
$options_categories = array();
$options_categories_obj = get_terms('post_tag');
var_dump($options_categories_obj);
foreach ($options_categories_obj as $category) {
$options_categories[$category->term_id] = $category->name;
}
I left that var_dump in there so you can see if you are actually getting returned terms.
Any boy know how to choose multiple categories use the theme options framework?
Hi, this is excellent! Only one question, why can I get the upload images box appear only when I use add_theme_page and it doesn’t work if I change it for add_pages_page or add_menu_page?
Thanks a lot!
P.S.: Sorry for my english, I’m from Uruguay :)
Read the post again. It’s under “Change the Menu Location”.
Sorry, I don’t know why I did not read that part of the post. Thanks for your time!
[…] can use to abstract the creation of Options panels: the two most mature ones (at first glance) are Options Framework from Devin Price, and the UpThemes Framework from Themes developer UpThemes. Both look good, are […]
hello
I’m trying to load all articles of selected category in select box.
Have you an idea ?
Thank you.
I believe you’d need to add multiple=”multiple” to your select box. I can look at adding it as a feature.
$posts = get_posts();
$posts_list = array();
foreach($posts as $post) {
$posts_list[$post->ID] = $post->post_title;
}
something like this?
and then add “posts_list” to “options”…
Hello,
I need the select box, I will return the string value and not the ID value, how can I do, below that I have in my options array.
$options[] = array( “name” => “Home Sidebar”,
“desc” => “you can select the sidebar of home page here.”,
“id” => $shortname.”_home_sidebar”,
“type” => “select”,
“options” => $active_sidebars,
“std” => “Blog Sidebar”
);
the options is dynamic, I don’t know the name of the sidebar
If you don’t know the name of the sidebar, how would you be able to generate an option that has the name of the sidebar?
I was hinting at the answer, but maybe I should just be specific. If you are able to generate $active_sidebars, you know all the keys and values. Just use the variable $active_sidebars again when you need to output the value somewhere else. e.g. $active_sidebars[(of_get_option(‘sidebar’)]
I’m not quite sure what you mean. You can store any key/value pair that you want. Save the key the same as the value if that’s what you want returned.
Hi Devin, nice work! I have just a little problem:
I want this in the admin sidebar:
-toplevel menu -> sublevelmenu1 => option panel1
-> sublevelmenu2 => option panel2
-> sublevelmenu3 => option panel3
I read your “change the menu location” note but i didn’t succeed to have a clean panel with color picker and others media uploaders.
Is it possible? How can i do that? thanks
No, different sections are done with the tabs. It would take really significant customizations in order to have separate menu items.
Ok so i’ll forget this idea and concentrate on one top level menu with some tabs in. Thanks a lot!
Hi! Having a problem with font-face in Typography. When I set the font-face it resets on default value (Arial). Have you ever had situation like this?
Thanks a lot.
I just verified that this is a bug in the plugin version. Thanks for reporting it. Should have a fix out soon.
Unfortunately, I see this bug in theme version too.
Filed a bug report for it. Will get fixed soon. Thanks.
Devin just sent you a pull request with this problem fixed. https://github.com/devinsays/options-framework-theme/pull/31
Thanks again for the great framework.
Thanks for the fix. Merged.
Now it’s good. Thanks a lot.
I haven’t had a problem with the font-face in Typography re-setting to the default value, however I noticed that the font-size re-sets itself to the default 9px after saving changes.
I also noticed that the font size was not being applied in the browser so in index.php I changed:
font:’.$typography[‘size’] .
to
font-size:’.$typography[‘size’] . ‘px;
What If I Want To ADD Custom Icons For Every Menu inside the frame ,, i maen some thing like this ,,
$options[] = array( “name” => “Main Setting”,
“icon” => “main.png”,
“type” => “heading”);
—
which Display the in menu like this ( [icon as img] Main Setting) .. ??
Like Woo theme frame work ,,
For the tabs? The easiest way is probably to just do it via options panel CSS. If you need it defined in the option, that’s customization land and you’re on your own. :)
Thanks devin for your help :D
hello, is it possible choose not images media in “media library” in uploader? not when i choose for example PDF file i see white screen.
It only allows image file types for the “image uploader”, but it also shouldn’t whitescreen if you upload a different filetype. I filed a ticket to look into it: https://github.com/devinsays/options-framework-plugin/issues/103
For the colorpicker, is there a way when calling the option to exclude the # sign? Right now it’s outputting as #111111 when I want it to output as 111111.
Great job on the theme by the way, this is a lifesaver.
Probably easiest way is to do str_replace when you get the value: http://php.net/manual/en/function.str-replace.php.
Why would you want to exclude the # sign?
Client uses phpthumb and a value in phpthumb will only accept the hex value without #. Working on workaround that doesn’t include phpthumb :)
Also, that’s what I figured, although the original colorpicker.js seems to accept non # values but I couldn’t figure a way to revert it back to that.
in start of loop ..
when i try to add selected option it give an error ..
i make it like >
<?php query_post('cat=’);?>
so what is the right way ?
query_posts(‘cat=1&showposts=4’);
when i try to add option like
query_posts(‘cat=echo of_get_option( ‘mhgoz_mcl_tb1_tit’ )&showposts=4′);
it gives error
Hi Devin, Thanks a lot making theme options that easy for guys like me, Well I have used the framework in few themes and I love it :)
Only thing that I want to do with it is that is it somehow possible to show theme options and a separate menu item instead of under appearance settings
Thanks for help in advance :)
This codex page explains how to hook menus into different places: http://codex.wordpress.org/Administration_Menus
However, it’s recommended to keep “Theme Options” under the appearance menu.
Great plugin Idea!!! I just tried installing the Options Theme (versus the plugin) and immediately ran into some problems. I did move over the entire admin folder, the functions.php snippet, and options.php. It IS working in that the data is spitting out on the front end correctly. BUT the dashboard admin area appears as if the javascript is not loading. The tabs do not work, the media uploader doesn’t work, color-picker doesn’t load, and the Basic and Advanced settings are stacked (instead of in tab-form). Lastly, the styling isn’t correct easier, as all of the inputs are smushed close together with no padding. It seems that the js isnt loading. Any idea why this is happening? I tried installing this on a few of my local themes with the same problem each time.
Tried to recreate the bug, but could not: http://www.screenr.com/zNC8
Try following the steps and again and make sure that all the files are getting moved over.
fixed it! Turns out if the directory your theme is in contains spaces, it causes that bug. Thanks for your help Devin and AWESOME work
[…] Options Framework Theme (by Devin Price) has been submitted here many times, especially after all the discussion on the NHP […]
Hello Devin,
Thanks a lot for this framework and I use this for few my themes, but 3 of my theme users experiencing an issue, when they hit the save button it says options saved but nothing changed..
Can you explain why this happens?
Hey Devin, thanks for the amazing framework. Is it possible to automatically populate the wp_options table with all of the default options when the user installs the theme for the first time?
Thanks
Yes, I did have that working correctly on an earlier version. I’ll file it as an issue to test.
Looking into this a bit more, and seems like setting the option defaults in the database simply on activation may not be the best practice: http://kovshenin.com/2012/never-set-defaults-in-the-database/#comment-9332
Do you know you can include a default it of_get_option is not set. Does that not work for you?
Yes!
Please don’t store the dafault value in database on activation.
And if you ever do this, please make it filterable, so if we don’t want it, we can just deactivate it.
No, I agree with Otto on this one. In fact, it looks like I need to remove some code.
hmm..
i read otto’s comments again, but i don’t really understand it.
is that means,when user click restore default, it will delete the database?
or if for example user only change 1 of 5 options, then only 1 options saved in database?
or both?
what do you think about modifying of_get_option and get the default value from optionsframework_options when there’s no database yet?
Good question about what to do when user clicks “reset”. Not sure, I supposed either would work.
But I think the main concern was about options automatically getting set on activation. In that case, the user would actually be navigating to the options page and setting them.
Dear Devin,
Tim here and I need some help. I’m trying to create a magazine style theme for a client using your theme options framework.
Specifically how to your the category select option. The website mockup is located here: http://store2.timothycaron.com
I can pull in the category title but not the post information using the same option as the title div.
Would you be so kind as to offer a solution? Thanks in advance for all your help.
Tim
Have you looked at the Options Framework theme defaults? It has a category option, and displays out the ID.
Dear Devin,
Tim here, I am using the category option as described to bring in the blog title, but becuase of the way I have it bringing in the most recent post it won’t work in the same way.
Thanks
Tim
Hi!
Thank you for this theme! I try to use ‘Options Framework Theme 1.0’ on WP 3.3.2. and I have issue with uploader. In general it works great, but it does not show default value ‘no entry’. It means that I can upload image and it becomes visible on web site, but when I remove it default value ‘no entry’ does not appear. Where could be the problem?
Thank you for advice!