我添加了自己的设置来更改字体。
这是我得到的代码。
$wp_customize->add_setting( 'calendar_title_font', array(
'default' => '',
'sanitize_callback' => 'skyrocket_text_sanitization',
'sanitize_js_callback' => 'skyrocket_google_font_sanitization',
'transport' => 'postMessage',
) );
$wp_customize->add_control( new Skyrocket_Google_Font_Select_Custom_Control( $wp_customize, 'calendar_title_font', array(
'label' => __( 'Font Family', 'blah' ),
'section' => 'calendar_title',
'input_attrs' => array(
'font_count' => '20',
'orderby' => 'popular',
),
) ) );JS代码
wp.customize( 'calendar_title_font', function( value ) {
value.bind( function( to ) {
$('h2.toolbar-title')
.css('font-family', to );
} );
} );选择性刷新
$wp_customize->selective_refresh->add_partial( 'calendar_title', array(
'selector' => 'h2.toolbar-title',
'settings' => 'calendar_title_font',
'render_callback' => function() {
echo get_setting( 'calendar_title_font' );
},
) );我做错了什么?当我更改字体时,我只需要更新标题所在的部分,即<h2>Title</h2>。但是我仍然有完整的定制器编辑窗口正在更新。显然selective_refresh出了点问题,我搞不清是什么东西。
谢谢你的帮助。
另外,对不起,我的英语不好。
发布于 2020-11-30 13:21:26
也许您需要使用与使用选择性刷新相同的setting_id。
你可以试试'calendar_title_font',...rest of the code
代码的...rest,而不是标题'calendar_title‘
https://stackoverflow.com/questions/65068042
复制相似问题