19

The answer that yes, the theme_mod functions will be slower, but not significantly, and the benefits outweigh the differences. Theme mods are stored as options. So, in essence, the theme_mod functions are wrappers around the options functions. First, understand that theme_mod settings are stored as an array in a single option, keyed to the specific theme ...


9

Here is one way to do it by extending the control you want to use. Below is an example where we extend the text control and add an extra description like the one seen here on the screenshot: function mytheme_customizer( $wp_customize ) { class Custom_Text_Control extends WP_Customize_Control { public $type = 'customtext'; public $extra =...


9

The base paradigm in WordPress is The Callback Handler. Actions, filters, widgets, metaboxes and so on … everything runs by registering specific callback handlers for some triggers. This is not always the most elegant way, but the one every beginner must learn, so stick to that paradigm, whenever you’re not sure what to do. So offer four actions: do_action(...


9

Have a look at: The Complete Guide To The WordPress Settings API (Part 8: Validation, Sanitisation, and Input II): add_settings_field( 'Checkbox Element', 'Checkbox Element', 'sandbox_checkbox_element_callback', 'sandbox_theme_input_examples', 'input_examples_section' ); function sandbox_checkbox_element_callback() { $...


9

Best place is the uploads directory - it'll be writable by the server, and it's the defacto directory for storing any user-generated/uploaded files: $dirs = wp_upload_dir(); $path = $dirs['basedir']; // /path/to/wordpress/wp-content/uploads


9

Try nav_menus instead of menus with remove_panel() function mytheme_customize_register( $wp_customize ) { //All our sections, settings, and controls will be added here $wp_customize->remove_section( 'title_tagline'); $wp_customize->remove_section( 'colors'); $wp_customize->remove_section( 'header_image'); $wp_customize->remove_section(...


8

Why one should consider other ... options Frameworks like "Option Tree" (there're also several others) shouldn't be used anymore. The "Theme Customization API" is what you should use now, as it also adds the possibility of live editing a Theme in the Theme Customizer and binding the Theme options to the "Theme Modification API". The "Settings API", which ...


8

For anyone still interested in customizer export/import functionality, we just released a new plugin on the wordpress.org repo that does exactly that! https://wordpress.org/plugins/customizer-export-import/ Don’t hesitate to let us know what you think!


8

These classes are generated by WordPress. For instance, if a user inserts an image in his post and says it must be aligned right, WP will generate code like this in the post: <img class="alignright" src="..."> Now, if your theme doesn't define the alignright class, the image won't be aligned right and the user won't get what he expects. You can ...


7

The page content for custom backgrounds is created in wp-admin/custom-background.php. There is no action available where the fields are printed. To add new fields we have to print JavaScript into the page footer. The action is 'admin_footer-appearance_page_custom-background'. To save those field values we have to hook into 'load-appearance_page_custom-...


7

For anyone who comes across this after WordPress 4.0 is released, custom controls are no longer necessary. This functionality is baked right into WordPress: https://core.trac.wordpress.org/ticket/27981.


7

The problem here is that you don’t allow PHP to read more than one value, because all values use the same name site_options[categorychoice], so they overwrite each other, and the last one wins. You need more brackets. Set the name attribute of your select element to site_options[categorychoice][], and all values will be read by PHP.


6

Theme mod settings are stored as a single database entry in the options table. For example, If I look in my wp_options table in a localhost install, and find the key of theme_mods_twentythirteen, then this is the content of it: a:3:{s:16:"header_textcolor";s:6:"220e10";s:12:"header_image";s:84:"http://localhost/wptrunk/wp-content/themes/twentythirteen/...


6

wp_add_inline_style() is intended to add additional CSS to an existing stylesheet. The idea is that you may need to dynamically alter the stylesheet - for instance, you have user-selected colours associated with categories and you would like to colour each category's title accordingly. You can't hardcode this since the colours in question are not known, but ...


6

The correct way to disable nav menus in the customizer is via the customize_loaded_components filter as documented on its hook reference page: /** * Removes the core 'Menus' panel from the Customizer. * * @param array $components Core Customizer components list. * @return array (Maybe) modified components list. */ function wpdocs_remove_nav_menus_panel(...


5

First, change your code into the following: $value = get_option( 'mytheme_value' ); query_posts ( "meta_key=post_views_count&orderby=meta_value_num&order=DESC&meta_value={$value}"); When you use single quotation marks, php isn't parsed in the string, and functions (like get_option) will never be called from within a string. Therefore, call the ...


5

I'm the lead dev for Redux Framework. This is because you use the same function name. You must change the add_another_section name to something less common. Otherwise you'll always get an error. That's unfortunately a limitation of PHP. One name per function per instance.


5

I think the problem is that you are using uppercase letters in the options id: footer-nav1_URL Try instead: footer-nav1_url In general you should avoid using uppercase letters in options names in WordPress.


5

Edit: Updated with the added context from your comment. You could do this with a custom Page template. In your theme, create a new file. In this example, my theme will be "mytheme2015," my new file is "template-holiday-card.php": in wp-content/themes/mytheme2015/template-holiday-card.php <?php /** * Template Name: Holiday Card */ Now, once you have ...


5

It depends on the theme itself. A theme may store some data in the database. For example, a theme may have an option called "Social Accounts" section in settings page and a field "Facebook Page URL" in it. If you fill the field and save settings, it will store this value to database. But, as a common practice, these type of data should be removed when you ...


4

Checkbox is possible. A example, I hope this help you. At first you must define the setting, via add_setting, important is the param type with value option. After this control the field via add_controland set the param type to checkbox. Alternative it is possible to use select. If I add a default value via std, then work it, also without this param. ...


4

Regardless of the platform (WordPress, Joomla!, Drupal) or the language (PHP, C++, VB) it's pretty much accepted/standard practice to break out code in to functional units. This includes not only functions and classes, but files as well. As @Toscho points out: The code is used in multiple places. It improves readability. It also makes it easier to: ...


4

What you're trying to do can be accomplished without ever editing the core files in OptionTree. Add your custom option type functions to your themes functions.php and the following code, as well. /** * Filter to add custom option types. * * @param array An array of option types. * @return array */ function add_custom_option_types( $types ) { ...


4

Try this: $options = get_option( 'theme' ); wp_localize_script( 'flexslider', 'flex_vars', array ( 'flex_auto' => ($options['slide-auto']) ? 'true' : 'false', 'flex_animation' => $options['slide-animation'], 'flex_direction' => $options['slide-direction'] ) ); Assuming slide-auto is the option you made a boolean. This script isn't tested, ...


4

Ok. Here's the correct bit of code, I got solution with: <select multiple="multiple" name="site_options[categorychoice][]"> <?php $option = get_option('site_options'); ?> <?php $args = array( 'orderby' => 'name', 'parent' => 0, 'exclude' => 1 ); $categories = get_categories( $args ); foreach ($...


4

never* execute code outside of hooks as you are more likely to call a function or use a variable before they were declared and initialized. your code should be function css() { if (ot_get_option('css', false) != false) { echo'<style>'.ot_get_option('css').'</style>'; } } add_action( 'wp_head', 'css', 100 ); *...


4

The only directory with guaranteed write access is the upload directory. Everything else might be protected. Nowadays, we deploy sites with Composer, keep everything under version control and create completely new sites with each deploy in order to be able to roll back the deployed site. That means that the directory will be created completely new with ...


4

Add Section to Theme Customizer: $wp_customize->add_section( 'parsmizban_options', array( 'title' => __( 'Theme Options', 'parsmizban' ), //Visible title of section 'priority' => 20, //Determines what order this appears in 'capability' => 'edit_theme_options', //Capability needed to tweak 'description' => __('...


3

I was having a similar issue, and it turned out that setting 'type' => 'option' for add_setting was the cause. Removing this solved my problem, and below is what I am currently using and it works just fine. $wp_customize->add_section('footer_social_media_section' , array( 'title' => __('Footer Social Media', 'dd_theme'), 'priority' =&...


3

Your problem is that you haven't included a sanitization function as the third parameter to register_settings on line 111. When no sanitization provided WordPress deletes the value of the option and creates a new one based only on what is passed in $_POST. Since unchecked checkboxes are not sent by the browser at all you end up with $options['show_admin_dev']...


Only top voted, non community-wiki answers of a minimum length are eligible