custom theme settings not working
-
Hi. I’m really sorry if it’s a double post but i haven’t found anything relelvant in the search or even on searches outside wordpress.
I’m recoding a theme to make it comply with wordpress standards and also to get rid of options-framework which is outdated, non developed anymore and kinda useless now.
I could make sections and settings appear in the customizer… When I change the settings, I can see the changes are applied in wordpress database, in wp-options, in “themename”… But nothing happens on the theme itself, either in live preview or when saved. It does that only on custom settings of the theme. The basic settings (like changing title and stuff) are working fine. Also, no error is reported with the debug mode.I’m pretty sure there’s something missing, but the tutorials and documentation didn’t give me any clues. I’m kinda new in this.
Here’s the codes used for one of them:
functions.php:
require( get_template_directory() . '/inc/customizer.php' );
/inc/customizer.php:
function my_theme_customize_register( $wp_customize ) { $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; $wp_customize->add_section( 'my_theme_header', array( 'title' => __( 'General', 'my-theme' ), 'priority' => 200 )); /* Search Box */ $options['g_search_box_id'] = array( "name" => __( "Display search box?", "my-theme" ), "desc" => __( "Display search box in the header?", "my-theme" ), "id" => "g_search_box_id", "type" => "checkbox", "std" => 1); $wp_customize->add_setting( 'my_theme[g_search_box_id]', array( 'default' => 1, 'type' => 'option' ) ); $wp_customize->add_control( 'my_theme_g_search_box_id', array( 'label' => $options['g_search_box_id']['name'], 'section' => 'my_theme_header', 'settings' => 'my_theme[g_search_box_id]', 'type' => $options['g_search_box_id']['type'], 'priority' => 11 ) ); // .... add_action( 'customize_register', 'my_theme_customize_register' );
the mattering part in header.php:
<?php if ( get_theme_mod('g_search_box_id', '1') === '1') { ?> <div id="top-search"> <form method="get" action="<?php echo home_url(); ?>/"> <input type="text" name="s" class="input-search" /><input type="submit" value="" id="submit"> </form> </div> <?php } ?>
In case you need, the full source code of the theme is here as it is.
Thanks for your help
- The topic ‘custom theme settings not working’ is closed to new replies.