Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How could I add a description to $wp_customize->add_control? I've found I really need to include a short description on some of the controls but it doesn't look like it's possible.

I noticed you can add a description to $wp_customize->add_section but that's only a tooltip.

This is ideally what I'd like to do, but unsure on how to output it and if this is possible:

$wp_customize->add_control( 'theme_options[some_option_name]', array(
    'label'   => 'This Is Some Option',
    'section' => 'theme_name_section',
    'type'    => 'text',
    'description' => 'Wish this existed', // this isn't possible
));
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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:

enter image description here

function mytheme_customizer( $wp_customize ) {
    class Custom_Text_Control extends WP_Customize_Control {
        public $type = 'customtext';
        public $extra = ''; // we add this for the extra description
        public function render_content() {
        ?>
        <label>
            <span><?php echo esc_html( $this->extra ); ?></span>
            <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
            <input type="text" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
        </label>
        <?php
        }
    }
    $wp_customize->add_section('customtext_section', array(
            'title'=>__('My Custom Text','mytheme'),
        )
    );     
    $wp_customize->add_setting('mytheme_options[customtext]', array(
            'default' => '',
            'type' => 'customtext_control',
            'capability' => 'edit_theme_options',
            'transport' => 'refresh',
        )
    );
    $wp_customize->add_control( new Custom_Text_Control( $wp_customize, 'customtext_control', array(
        'label' => 'My custom Text Setting',
        'section' => 'customtext_section',
        'settings' => 'mytheme_options[customtext]',
        'extra' =>'Here is my extra description text ...'
        ) ) 
    );
}
add_action( 'customize_register', 'mytheme_customizer' ,10,1);

It is helpful to check out the source of the WP_Customize_Control class:

https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-customize-control.php

Hope this helps.

share|improve this answer
    
Fantastic, thanks! I knew it had to be as simple as this –  Andrew Mar 10 '13 at 20:14
    
The code is not saving the input value - maybe I have a bug somewhere that is preventing it to be saved, maybe a wrong index? –  birgire Mar 10 '13 at 20:22
    
I only grabbed the relevant bits from your code that I needed, so mine is working correctly. I think it could be the type in your example. Should be customtext not customtext_control I think –  Andrew Mar 10 '13 at 23:33
    
ok great to hear it was somewhat useful ;-) –  birgire Mar 11 '13 at 1:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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