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?

2 Answers 2

1

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 );
3
  • Note that get_theme_mods() is not currently compatible with the Customizer preview. See core.trac.wordpress.org/ticket/24844 Oct 21, 2017 at 8:02
  • There is no mention in question where to get this settings. Oct 21, 2017 at 12:54
  • The question is how to get all of the theme mods using the Customizer API. Oct 21, 2017 at 17:11

Your Answer

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

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