Wordpress自定义程序-替换get_theme_mod中的文本


Wordpress customizer - replace text in get_theme_mod

我在Wordpress主题和页脚段落中有页脚。

它看起来像这样:

<p>lt;?php echo get_theme_mod("site_intro")>lt/p>

当您在自定义程序中时,可以选择更改页脚中的文本
我希望在默认情况下显示,例如:
版权所有2014。

这是默认文本,如果用户更改,文本将被替换版权所有2014,并且将是用户设置的文本。

我需要在哪里制作一些代码,在footer.php,functions.php中,customizer的其余代码在哪里?

这是用if-else语句完成的,还是Wordpress中有一些预制代码?

这是functions.php

函数theme_customize_register($wp_customize){if(class_exists('WP_Customize_Control')){类PTD_Textarea_Control扩展了WP_Customize_Control{公共函数render_content(){?><标签><span class=";自定义控件标题">lt;?php echo esc_html($this->标签)>lt/span><textarea class=";大文本";cols=";20〃;rows=";5〃<?php$this->链接()>gt;<?php echo esc_textarea($this->value())><text区域><标签><?php}}}$wp_customize->add_setting("site_intro",数组('default'=>'','transport'=>'postMessage));$wp_customize->add_section('theme_site_info',数组('title'=>'页脚信息','主题','description'=>'自定义页脚','主题',"优先级"=>20,));$wp_customize->add_control(新PTD_Textarea_control($wp_customize,'site_intro_control',数组('label'=>'网站页脚,主题,'section'=>'主题_站点_信息',"设置"=>"site_intro')));}add_action('customize_register','theme_customize_register])

您可以使用get_theme_mod函数的第二个参数。您可以将默认值作为第二个参数传递,如果您的设置以前没有保存,则会返回该参数。

<p><?php echo get_theme_mod('site_intro', 'Copyright '.date('Y'));

我没有看到任何代码,所以我不能告诉你如何更新函数以获得你想要的。但我会根据目前所见给出解决方案。

您可以在页脚中执行此操作。

<?php
     $text = get_theme_mod('site_intro');
     if(empty($text){
            $text = 'Copyright '.date('Y'); //If you just want 2014 use Copyright 2014
     }
?>
<p><?php echo $text; ?></p>