0

I have successfully added a section to the Theme Customizer, can change the header image of a certain page. But now I want to add a different section for another page, but the first section is always overwritten.. The ID's should be well linked.

<?php

function af_customize_register($wp_customize){

  // header image section

  $wp_customize->add_setting('front_header_image', array(
    'default' => 'http://******.be/wp-content/uploads/2017/04/about-header-1200.jpg',
    'transport' => 'refresh'
  ));

  $wp_customize->add_section('front_header_image_section', array(
    'title' => 'Frontpage Header',
    'description' => 'Add an image to the front page.',
    'priority' => '1'
  ));

  $wp_customize->add_control(
       new WP_Customize_Image_Control(
           $wp_customize,
           'image',
           array(
               'label'      => 'Upload image to the frontpage',
               'section'    => 'front_header_image_section',
               'settings'   => 'front_header_image'
           )
       )
   );

   // archive image section
   $wp_customize->add_setting('archive_header_image', array(
     'default' => 'http://******.be/wp-content/uploads/2017/04/about-header-1200.jpg',
     'transport' => 'refresh'
   ));

   $wp_customize->add_section('archive_header_image_section', array(
     'title' => 'Archive Headers',
     'description' => 'Add an image to an archive page.',
     'priority' => '10'
   ));

   //
   $wp_customize->add_control(
        new WP_Customize_Image_Control(
            $wp_customize,
            'image',
            array(
                'label'      => 'Upload image to archive page',
                'section'    => 'archive_header_image_section',
                'settings'   => 'archive_header_image'
            )
        )
    );

}

?>

1 Answer 1

0

In order to create a section, it must have a control, and each control requires a unique control id, you are passing the same control id image to both of your controls and hence it will create a control for the last one, and ignore the previous one. Therefore your first section does not get any control and it is being overridden. In short you need to pass unique control ids to your controls inside WP_Customize_Image_Control.

1
  • Oh thanks, had no idea 'image' was the ID. Thought it was because it's an image control..
    – Greg
    Commented May 9, 2017 at 7:50

Your Answer

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

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