4

If I print the value of get_theme_mod( 'enable_sleek_header', false ) it is always the previously saved value. If I print the same thing in the header of the theme, it returns the value from customizer.

  • Is it the expected behaviour?
  • Am I using the wrong hook?

Thanks


<?php

add_action( 'after_setup_theme', 'pagespeed_register_menus' );


    function pagespeed_register_menus() {

        //Not getting the modified theme_mod from the customizer without saving.
        register_nav_menus( array(
            'secondary' => __( 'Navigation above header', 'page-speed' ),
        ) );

        if ( get_theme_mod( 'enable_sleek_header', false ) ) {
            register_nav_menus( array(
                'header' => __( 'Navigation menu in header', 'page-speed' ),
            ) );
        } else {
            register_nav_menus( array(
                'primary' => __( 'Navigation below header', 'page-speed' ),
            ) );
        }
        register_nav_menus( array(
            'footer_links' => __( 'Footer links', 'page-speed' ),
        ) );

    }
0

To register my menus I usually use the init action hook, maybe you could try it.

add_action( 'init', 'pagespeed_register_menus' );

instead of

add_action( 'after_setup_theme', 'pagespeed_register_menus' );

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.