Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress theme customizer - can't add section/settings

Tags:

php

wordpress

I'm trying to modify the Worpdress theme customizer by adding sections and settings but no matter what I add in my functions.php file, nothing ever shows up in the customizer.

Example:

function starter_customize_register( $wp_customize ) 
{
    $wp_customize->add_section( 'mytheme_new_section_name' , array(
    'title'      => __( 'Visible Section Name', 'starter' ),
    'priority'   => 30, ) );    
}
add_action( 'customize_register', 'starter_customize_register');

I would have expected this to add a section with the chosen name but the only things I see are the two initial sections from Wordpress (site title & tagline, static front page).

I had found a pretty nice tutorial here (http://code.tutsplus.com/series/a-guide-to-the-wordpress-theme-customizer--wp-33722). I followed every step and even took their example theme but there again, no new sections or settings are displayed.

Makes me wonder if something is wrong with my configuration.

I'm using a wordpress network/multisite, don't know if that's relevant.

Any idea?

Thanks Laurent

like image 950
Laurent Avatar asked Apr 04 '15 12:04

Laurent


Video Answer


1 Answers

You need to add setting(s) and control(s) to make it work:

function starter_customize_register( $wp_customize ) 
{
    $wp_customize->add_section( 'starter_new_section_name' , array(
        'title'    => __( 'Visible Section Name', 'starter' ),
        'priority' => 30
    ) );   

    $wp_customize->add_setting( 'starter_new_setting_name' , array(
        'default'   => '#000000',
        'transport' => 'refresh',
    ) );

    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array(
        'label'    => __( 'Header Color', 'starter' ),
        'section'  => 'starter_new_section_name',
        'settings' => 'starter_new_setting_name',
    ) ) );
}
add_action( 'customize_register', 'starter_customize_register');

Reference: Theme Customization API.

like image 152
d79 Avatar answered Sep 19 '22 16:09

d79