4

I've been working on this for a long time but can't get it fixed. I'm simply trying to get the function below to work but it's refusing to do that.

I have put it in functions.php of my theme.

function options( $wp_customize ) {
    $wp_customize->add_control(
        'copyright_textbox',
        array(
            'label' => 'Copyright text',
            'section' => 'example_section_one',
            'type' => 'text'
        )
    );
}
add_action( 'customize_register', 'options' );

About to give up but my last hope is SO. What is hating on my in this code and what do I need to do to fix it?

5
  • Where is the other part of code ? Section and settings ?
    – Sumit
    May 31, 2016 at 17:57
  • This is the only code I have.. Not sure, I just started working with WP
    – J. Doe
    May 31, 2016 at 18:07
  • Yes, @Sumit is right, you probably forget to register at least the "setting" in the case that the section already exists.
    – Capiedge
    May 31, 2016 at 18:08
  • @Capiedge Do you know how I can setup the setting? Sorry for asking
    – J. Doe
    May 31, 2016 at 18:13
  • See this clean example on codex codex.wordpress.org/Plugin_API/Action_Reference/…
    – Sumit
    May 31, 2016 at 18:22

1 Answer 1

11

You always need to be sure that three things are defined (section, setting and control).

If you are adding a control to an already defined section, i.e. title_tagline, then you don't need to re-register it, but always define the setting and the control.

//adding setting for copyright text
add_action('customize_register', 'theme_copyright_customizer');

function theme_copyright_customizer($wp_customize) {
    //adding section in wordpress customizer   
    $wp_customize->add_section('copyright_extras_section', array(
        'title'          => 'Copyright Text Section'
    ));

    //adding setting for copyright text
    $wp_customize->add_setting('text_setting', array(
        'default'        => 'Default Text For copyright Section',
    ));

    $wp_customize->add_control('text_setting', array(
        'label'   => 'Copyright text',
        'section' => 'copyright_extras_section',
        'type'    => 'text',
    ));
}

Hope it helps!

2
  • Do you know how I can add multiple fields?
    – J. Doe
    May 31, 2016 at 19:02
  • Register more add_control (and if you need, more add_setting) and link them to the same section. BTW if you consider that the answer is correct, accept it as such, please.
    – Capiedge
    May 31, 2016 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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