Archived topic
how to get customizer value/setting
9 replies · Started by Marco on July 25, 2022
Hello
how can I get the e.g. the featured image location setting in the blog settings of the customizer - it's either above title or below title and I like to get the setting in my functions.php file.
thanks
Hi there,
you can use the option_generate_blog_settings filter to set the various GPP blog options, including the featured image location:
https://docs.generatepress.com/article/option_generate_blog_settings/
there seems to be a misunderstanding - I do not want to set it, I'd like to retrieve the value from the customizer - something like: get_option( 'generate-blog-settings' )
Sorry my bad ... misread that completely.
Thats correct you can use get_option like so:
$settings = wp_parse_args(
get_option( 'generate_blog_settings', array() ),
generate_blog_get_defaults()
);
you can then check the array for the settings listed in the article i provided above.
you can always var_dump($settings) to see all of them.
I've added a custom setting to the customizer in the general panel - it shows up right after the smooth scroll checkbox. however, I do not see the newly added setting - what am I missing?
Thank you in advance for your input.
this is the code to retrieve the settings:
$settings = wp_parse_args( get_option( 'generate_general_settings', array() ), generate_get_defaults() );
this is the code I used to add a new checkbox:
function prefix_add_customizer_options( $wp_customize ) {
// Enable/disable lazy loading
$wp_customize->add_setting ( 'generate_settings[lazy_load]',
array (
'default' => false,
'type' => 'option',
'sanitize_callback' => 'generate_sanitize_checkbox',
)
);
$wp_customize->add_control ( 'generate_settings[lazy_load]',
array (
'type' => 'checkbox',
'label' => __( 'Enable lazy load', 'generatepress' ),
'description' => __( 'Set if you like to enable lazy loading.', 'generatepress' ),
'section' => 'generate_general_section',
'priority' => 99
)
);
}
add_action( 'customize_register','prefix_add_customizer_options' );
Your code worked for me:
That's what I'm saying - however if you want to retrieve the value like $settings = wp_parse_args( get_option( 'generate_general_settings', array() ), generate_get_defaults() );, the new setting is not in that $settings array for some reason?!
Aah sorry.
Try this:
$settings = wp_parse_args( get_option( 'generate_settings', array() ), generate_get_defaults() );
same this - setting doesn't show up in that array - neither of the following works although the setting shows up in the backend:
echo 'MOD: ' . get_option( 'generate_settings[lazy_load]');
echo 'MOD: ' . get_theme_mod( 'generate_settings[lazy_load]' );
$settings = wp_parse_args( get_option( 'generate_general_settings', array() ), generate_get_defaults() );
$settings = wp_parse_args( get_option( 'generate_settings', array() ), generate_get_defaults() );
once I've checked/unchecked the setting it now shows up only with this:
$settings = wp_parse_args( get_option( 'generate_settings', array() ), generate_get_defaults() );
all the other ones don't work - what I was wondering is why this isn't working: $settings = wp_parse_args( get_option( 'generate_general_settings', array() ), generate_get_defaults() ); from what I understand this should get the general settings panel and it actually does but not the custom setting that I've added
When i do this:
$settings = wp_parse_args( get_option( 'generate_settings', array() ), generate_get_defaults() );
I see this: