猿问

Wordpress 定制器预览不会刷新functions.php

所以我遇到了定制器预览没有完全刷新的问题。只有当我手动刷新页面时,我才能看到我的更改。我的一些代码有助于在下面解释。


对于我的定制器设置,我的代码看起来像这样


$wp_customize->add_section( 'theme_layout', array(

        'title' => __( 'Layout', 'theme' ),

        'priority' => 30

) );


$wp_customize->add_setting( 'theme_header_layout', array(

         'default' => 'default',

         'transport' => 'refresh',

) );


$wp_customize->add_control( new WP_Customize_Control( $wp_customize,

'theme_header_layout', array(

          'label' => __( 'Header', 'theme' ),

          'section' => 'theme_layout',

          'settings' => 'theme_header_layout',

          'type' => 'select',

          'choices' => array(

               'default' => 'default',

               'special_header' => 'Special Header',

           )

) ) );

现在在我的functions.php中我有这样的代码


//this is the code that doesn't seem to execute when the customizer refreshes

if ( 'special_header' == get_theme_mod( 'theme_header_display' ) ):

   function theme_special_header( $items ) {

       $items .= do_shortcode('[special_header_shortcode]');//This shortcode exists I just didnt bother mentioning it here

   }

   add_action( 'wp_nav_menu_secondary-menu_items', 'theme_special_header' );//Adds shortcode to menu with id of secondary-menu

endif;

当我转到定制器并选择“特殊标题”时,这一切都很好接受,定制器会刷新,并且在完全刷新页面之前我看不到我的更改。


人到中年有点甜
浏览 119回答 1
1回答
随时随地看视频慕课网APP
我要回答