1

I'm adding custom options to my theme using the customizer api. For example:

$wp_customize->add_setting( 'header_textcolor' , array(
    'default'   => '#000000'
) );

$wp_customize->add_setting( 'footer_textcolor' , array(
    'default'   => '#333333'
) );

Is it possible to return an array of all my custom settings from customizer?

0

Yes. You can get an array of all registered settings via $wp_customize->settings(). If you want to display them all you could do this:

if ( is_customize_preview() ) {
    global $wp_customize;
    $theme_mods = array();
    foreach ( $wp_customize->settings() as $setting ) {
        if ( 'theme_mod' === $setting->type ) {
            $theme_mods[ $setting->id ] = $setting->value();
        }
    }
    echo '<pre>' . json_encode( $theme_mods, JSON_PRETTY_PRINT ) . '</pre>';
}
0

Try this:

$all_settings = get_theme_mods();
print_r( $all_settings );
  • Note that get_theme_mods() is not currently compatible with the Customizer preview. See core.trac.wordpress.org/ticket/24844 – Weston Ruter Oct 21 '17 at 8:02
  • There is no mention in question where to get this settings. – Misha Rudrastyh Oct 21 '17 at 12:54
  • The question is how to get all of the theme mods using the Customizer API. – Weston Ruter Oct 21 '17 at 17:11

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.