I have developed a theme options page which is a submenu page of appearance. But now i like to know how what i need to do so the theme options are also editable in the theme->customize interface. (customize.php).

I tried a simple test by adding this to functions.php, to see if the customize menu is altered but no luck

//for customize.php
function mytheme_customize_register( $wp_customize ) {
   //All our sections, settings, and controls will be added here
   //1. Define a new section (if desired) to the Theme Customizer
      $wp_customize->add_section( 'mytheme_options', 
            'title' => __( 'MyTheme Options', 'ppr' ), //Visible title of section
            'priority' => 35, //Determines what order this appears in
            'capability' => 'edit_theme_options', //Capability needed to tweak
            'description' => __('Allows you to customize some example settings for MyTheme.', 'ppr'), //Descriptive tooltip

      //2. Register new settings to the WP database...
      $wp_customize->add_setting( 'link_textcolor', //No need to use a SERIALIZED name, as `theme_mod` settings already live under one db record
            'default' => '#2BA6CB', //Default setting/value to save
            'type' => 'theme_mod', //Is this an 'option' or a 'theme_mod'?
            'capability' => 'edit_theme_options', //Optional. Special permissions for accessing this setting.
            'transport' => 'postMessage', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)?

add_action( 'customize_register', 'mytheme_customize_register' );
//end cutomize.php


  • Whats not working? Is it adding any fields to the customizer or is nothing working? – Bryan Willis Aug 24 '14 at 11:22
  • @willow, well in my case it isn't working i don't see the section My theme options. !link – alex Aug 24 '14 at 11:43

You need to add a control to it.

function mytheme_customize_register( $wp_customize ) {

  $wp_customize->add_section( 'mytheme_options', 
        'title' => __( 'MyTheme Options', 'ppr' ),
        'priority' => 35,
        'description' => __('Allows you to customize some example settings for MyTheme.', 'ppr'),

$wp_customize->add_setting( 'link_textcolor', array(
    'default' => get_option( 'your_theme_page_option_value' ), THIS IS THE OPTION NAME YOU CREATED WITH YOUR OPTIONS PAGE CODE
    'type' => 'option',  // FOR OPTIONS USE OPTION
    'capability' => 'edit_theme_options',
    'transport' => 'refresh', // WILL REFRESH INSTEAD OF JS. YOU HAVE TO WRITE JS TO MAKE UPDATE INSTANT... ITS A PAIN IN THE ASS http://codex.wordpress.org/Plugin_API/Action_Reference/customize_preview_init
) );

$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array(
    'label'        => __( 'Link Text Color', 'ppr' ),
    'section'    => 'mytheme_options', // ID OF SECTION ABOVE
    'settings'   => 'link_textcolor', // ID OF SETTINGS ABOVE
) ) );

 add_action( 'customize_register', 'mytheme_customize_register' );

Alex make sure you are including the options in your templates otherwise you wont see any changes. For example if you want to us the options in all templates make sure you are actually putting the option inside the header or all the files that will need changes.

So for the above code I would use something like this and place it in my header.php or even just in a function that uses the wp_head action if it's for styles.

function mytheme_customizer_styles() {
        $link_text_color = get_option('your_theme_page_option_value'); // THIS IS THE OPTION VALUE THAT YOU CREATED WITH SETTINGS API AND YOUR CUSTOM OPTIONS PAGE AND IS ALSO THE NAME OF THE OPTIONS DEFINED IN THE `add_setting` field above.
    <style type="text/css" id="mytheme-customizer-admin-header-css">
         .link-text-color { color:  <?php echo $link_text_color; ?>; }
add_action( 'wp_head', 'mytheme_customizer_styles', 9999); // JUST MAKE SURE THE PRIORITY IS LATE ENOUGH SO ITS NOT OVERRIDEEN
  • Just code is a bad answer. Please, explain what the code does and why it answers the question. – cybmeta Aug 24 '14 at 13:01
  • I still recommend using styles Plugin. All this code is complete waste of time! – Bryan Willis Aug 24 '14 at 13:11
  • that is your opinion. I prefer code my own, especially if you are going to add only a few customization options there is no reason to install a heavier plugin. Also, that plugin only support a very few themes, so it is not a solution at all from a developer point of view. – cybmeta Aug 24 '14 at 13:20
  • tx willow, i indeed was missing a control. As i said i have already created an options page which works ok. To make my theme a bit user friendly i like the options also be accesible through the optimize.php – alex Aug 24 '14 at 13:40
  • hi guys, how do i save the option values. Because now it always saves the default values i have set. – alex Aug 24 '14 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.