0

Please let me know if I'm missing something here - I try to create multiple customizer settings using for loop, they don't show up in the customizer though. Here's the code:

for ( $i = 1; $i < 7; $i++ ) :

    $wp_customize->add_setting( 'home_features_boxes_icon_' . $i, array(
        'default'           => '',
        'type'              => 'theme_mod',
        'capability'        => 'edit_theme_options',
        'sanitize_callback' => 'esc_html',
    ) );
    $wp_customize->add_control( 'home_features_boxes_icon_' . $i . '_c', array(
        'settings'          => 'home_features_boxes_icon' . $i,
        'section'           => 'home_features_boxes',
        'type'              => 'text',
        'label'             => esc_html__( $i . ' - Box Icon', 'lucathemes' ),
    ) );

endfor;

Section name is correct, settings added outside the for loop are working fine.

Thanks, Luca

0

You are missing _ in add_control paramater: settings. The settings parameter should be home_features_boxes_icon_' . $i

Full code here:

for ( $i = 1; $i < 7; $i++ ) :

    $wp_customize->add_setting( 'home_features_boxes_icon_' . $i, array(
        'default'           => '',
        'type'              => 'theme_mod',
        'capability'        => 'edit_theme_options',
        'sanitize_callback' => 'esc_html',
    ) );
    $wp_customize->add_control( 'home_features_boxes_icon_' . $i . '_c', array(
        'settings'          => 'home_features_boxes_icon_' . $i,
        'section'           => 'home_features_boxes',
        'type'              => 'text',
        'label'             => esc_html__( $i . ' - Box Icon', 'lucathemes' ),
    ) );

endfor;

On the side note: esc_html is not a sanitization function. Use sanitize_text_field for text fields.

  • What would I do without smart people :) Thank you! – LucaThemes Jan 8 '18 at 18:16

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.