1

I'm using a commercial theme that has it's theme settings in WordPress's appearance/customizer. They call their settings through a function like this: (this is only part of the function which is about 400 lines long)

function customizer_library_gateway_options() {
    // Home
    $section = 'home';

    $sections[] = array(
        'id'            => $section,
        'title'         => __( 'Home', 'gateway' ),
        'priority'      => '20',
        'description'   => __( 'Home Page Options.', 'gateway' ),
        'panel'         => $panel
    );

    $options['home_hero_bg'] = array(
        'id'                => 'home_hero_bg',
        'label'             => __( 'Home Background Image', 'gateway' ),
        'section'           => $section,
        'type'              => 'image',
        'default'           => $imagepath . 'hero-bg.jpg',
        'active_callback'   => 'is_front_page'
    );

    $options['bg_attachement'] = array(
        'id'                => 'bg_attachement',
        'label'             => __( 'Select the behavior of the background image.', 'gateway' ),
        'section'           => $section,
        'type'              => 'select',
        'choices'           => $bg_attachment,
        'default'           => 'fixed',
        'active_callback'   => 'is_front_page'
    );

    $options['home_hero_bg_color'] = array(
        'id'                => 'home_hero_bg_color',
        'label'             => __( 'Home Hero background color if no image is being used.', 'gateway' ),
        'section'           => $section,
        'type'              => 'color',
        'default'           => $primary_color,
        'active_callback'   => 'is_front_page',
        'transport'         => 'postMessage'
    );

    $options['home_posts_title'] = array(
        'id'                => 'home_posts_title',
        'label'             => __( 'Enter the home featured posts section title', 'gateway' ),
        'section'           => $section,
        'type'              => 'text',
        'default'           => 'Featured Posts',
        'active_callback'   => 'is_front_page',
        'transport'         => 'postMessage'
    );

    $options['home_posts_cat'] = array(
        'id'                => 'home_posts_cat',
        'label'             => __( 'Home Posts Category', 'gateway' ),
        'section'           => $section,
        'type'              => 'select',
        'choices'           => $options_cats,
        'default'           => '',
        'active_callback'   => 'is_front_page'
        );
    }
add_action( 'init', 'customizer_library_gateway_options' );

My question is: How can I add to this array through my child theme so I can add a logo option? I don't necessarily want to re-declare the whole function if I can just add my array insertion:

I was thinking add_filter but I'm not sure. This is what I tried in my child theme functions.php:

function customizer_library_gateway_home_logo() {

    $options['home_logo'] = array(
        'id'        => 'home_logo',
        'label'     => __( 'Logo', 'gateway' ),
        'section'   => 'home',
            'type'      => 'image',
            'default'   => $imagepath . 'logo.png'
        ); 

    }

    add_filter( 'customizer_library_gateway_options', 'customizer_library_gateway_home_logo' );

However, no change is made to the theme customizer. If I add the home_logo entry directly in the theme's original file it does work. Maybe there is a different action I should be using?

0

I might have a solution for you.

But, consider first using the default WordPress custom logo support. You just need to add this to your functions.php file:


function theme_prefix_setup() {

    add_theme_support( 'custom-logo' );

}

add_action( 'after_setup_theme', 'theme_prefix_setup' );

See more details about add_theme_support( 'custom-logo' ); at https://codex.wordpress.org/Theme_Logo.

Now, if you click Appearance > Customize, under Site Identity you will se the new Logo field.

If the solution above doesn't fit you, keep reading...

I tested the code below and it works fine (of course I changed it to fit some of your needs).


/**
 * @param object    $instance
 */
function customize_customize_page( $instance ) {

    // Set the args. You do not need to set 'type' key here.
    $args = array(
        'priority' => 0,
        'section' => 'home',
        // 'settings' => 'home',
        'label' => __( 'Logo' ),
        'description' => __( 'Description' ),
    );

    // Here we instance WP_Customize_Image_Control class and set its paramaters.
    // See that here is where you choose your option ID.
    $instance->add_control( new WP_Customize_Image_Control( $instance, 'home_logo', $args ) );

}

add_action( 'customize_register', 'customize_customize_page', 199, 1 );

If the code above won't work you should try uncommenting the key 'settings' and try again.
  • I don't really want the custom logo option, so I tried your 2nd function, which looked promising. Unfortunately, with or without settings, it completely eliminates the "home" section from the theme options in customization. – rudtek Dec 19 '16 at 19:24

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.