How to reset (clear) theme settings
I’ve found the solution, maybe it’ll be useful to anyone: function reset_mytheme_options() { remove_theme_mods(); } add_action( ‘after_switch_theme’, ‘reset_mytheme_options’ );
I’ve found the solution, maybe it’ll be useful to anyone: function reset_mytheme_options() { remove_theme_mods(); } add_action( ‘after_switch_theme’, ‘reset_mytheme_options’ );
Modern answer to this question: We have WP_Customize_Media_Control control in WP since 4.2 that gives you the attachment id. This answer was posted on I similar question. You can see the documentation for WP_Customize_Media_Control here. Exemple of use: $wp_customize->add_setting( ‘my_menu_image’ ); $wp_customize->add_control( new \WP_Customize_Media_Control( $wp_customize, ‘storms_menu_image_ctrl’, array( ‘priority’ => 10, ‘mime_type’ => ‘image’, ‘settings’ => … Read more
Sanitization via the sanitize_callback function takes place when you save the the theme mod. Retrieving a theme mod via get_theme_mod() (which runs the theme_mod_{$name} filter) does not use the sanitize_callback function. So, whatever you’ve set $_GET[‘header_layout’] to will be used regardless of whether it is valid or not. From wp-includes\theme.php: /** * Retrieve theme modification … Read more
If you always want a page refresh, then all you have to do is simply remove this line: $wp_customize->get_setting( ‘blogname’ )->transport=”postMessage”; Or explicitly set it to refresh: $wp_customize->get_setting( ‘blogname’ )->transport=”refresh”; By doing this, selective refresh will never get invoked to refresh the partial, and it will skip straight to the full refresh. Note it is … Read more
Setting the default when registering the setting doesn’t make it the default on output, it just makes it the default value when the customiser is opened. To provide a default before the customiser is opened/saved you pass it as a second argument to get_theme_mod(): <?php echo get_theme_mod(‘home_header_title’, __(‘Clean. Simple. Sincere’, ‘sincere’) ); ?> This can … Read more
You have to inline the css into your theme. CSS is read-only and can’t updated to use the update hex colors for your header. <?php echo get_theme_mod( ‘header_textcolor’ );?> 100%);”> So find the div in your theme called navbar-default and update it to this: <div style=”background:#<?php echo get_theme_mod( ‘header_textcolor’ );?>”> class=”navbar-default”>
The debugger tells me that get_theme_mod() is returning ‘false’, when I expect it to return the value of the selected item. get_theme_mod() isn’t working because when you registered the setting, you set the type to option: $wp_customize->add_setting(‘title_font’, array( ‘default’ => ‘Roboto Slab’, ‘capability’ => ‘edit_theme_options’, ‘type’ => ‘option’, ‘transport’ => ‘postMessage’ )); The possible values … Read more
I think the problem is simply this line: ‘type’ => ‘option’, You should remove it, because the default is: ‘type’ => ‘theme_mod’, since you want to use get_theme_mod(). You should also consider: prefixing these color settings slugs, to make them more unique. using for example: ‘sanitize_callback’ => ‘sanitize_hex_color’, in your settings setup for sanitazion. ps: … Read more
The most robust way to do this is to do JavaScript-based instantiation of the sections, controls, and settings dynamically in response to the URL being previewed. Since you can navigate around the site in the preview, this will ensure that the post/page-specific sections and controls will be created as you need them when you navigate … Read more
I’ve documented how to do this in my post Navigating to a URL in the Customizer Preview when a Section is Expanded, though naturally you’d just use panels instead of sections. This should get you what you want: (function ( api ) { api.panel( ‘my_panel_id’, function( panel ) { panel.expanded.bind( function( isExpanded ) { if … Read more