假设您正在使用支持WP定制器的主题:使用定制器。php文件(可在子文件夹“inc”中找到,或执行搜索,主题不同。拥有=Customizer API)
因此,在自定义程序中。php-添加以下内容:
// Add to customizer.php inside function your_customizer($wp_customize) {}
$wp_customize->add_setting(
\'live_in_ctc\',
array(
\'default\' => \'\',
\'type\' => \'theme_mod\',
\'capability\' => \'edit_theme_options\',
\'transport\' => \'postMessage\',
\'sanitize_callback\' => \'esc_url_raw\'
)
);
$wp_customize->add_control(
\'live_in_ctc\',
array(
\'label\' => \'Live In Tel\',
\'section\' => \'title_tagline\', // Site Identity section
\'type\' => \'url\',
\'priority\' => \'15\'
)
);
$wp_customize->add_setting(
\'live_in_label\',
array(
\'default\' => \'\',
\'type\' => \'theme_mod\',
\'capability\' => \'edit_theme_options\',
\'transport\' => \'postMessage\',
\'sanitize_callback\' => \'esc_attr\'
)
);
$wp_customize->add_control(
\'live_in_label\',
array(
\'label\' => \'Live In Label\',
\'section\' => \'title_tagline\', // Site Identity section
\'type\' => \'text\',
\'priority\' => \'16\'
)
);
现在,查找customizer。js。通常与customizer位于同一文件夹中。php(文件名因主题而异。请查找“customizer”一词)。
将此添加到customizer。函数中的js($):
wp.customize(\'live_in_label\', function(value) {
value.bind(function(to) {
$(\'.classname a\').text(to); // wrap your h3 in a div with .classname
});
});
更改:
<h3>Live In Care: <a href="tel:<?php the_field(\'live_in_ctc\'); ?>"><?php the_field(\'live_in_label\'); ?></a></h3>
收件人:
<div class="classname"><h3>Live In Care: <a href="tel:<?php echo get_theme_mod(\'live_in_ctc\'); ?>" title="telephone number"><?php echo get_theme_mod(\'live_in_label\'); ?></a></h3></div>
要允许电话号码/标签显示在整个站点中,请尝试在标题中添加“收件人:”更新。php,在最底层。先把原文注释掉。测试并查看发生了什么。我打赌需要额外的css才能获得正确的渲染数字。