GET_THEME_MOD不会在After_Setup_Theme挂钩中返回主题定制器预览的新值

时间:2018-01-01 作者:Satish Gandham

如果我打印get_theme_mod( \'enable_sleek_header\', false ) 它始终是以前保存的值。如果我在主题的标题中打印相同的内容,它将从customizer返回值。

这是预期的行为吗谢谢

<小时>

<?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\' ),
        ) );

    }

1 个回复
SO网友:Friss

为了注册我的菜单,我通常使用init操作挂钩,也许你可以试试。

add_action( \'init\', \'pagespeed_register_menus\' );
而不是

add_action( \'after_setup_theme\', \'pagespeed_register_menus\' );

结束

相关推荐