我在 WordPress 主题和页脚段落中有页脚。
它看起来像这样:
<p><?php echo get_theme_mod( 'site_intro' ); ?></p>
当您在定制器中时,可以选择更改页脚中的文本。
我想默认显示例如:
版权所有 2014。
这是默认文本,如果用户更改此文本,文本将替换版权所有2014,并且将是用户设置的文本。
我需要在 footer.php、functions.php 中编写一些代码,定制器的其余代码在哪里?
这是用if else语句制作的,还是Wordpress中有一些预制代码?
这是functions.php
function theme_customize_register( $wp_customize ) { if ( class_exists( 'WP_Customize_Control' ) ) { class PTD_Textarea_Control extends WP_Customize_Control { public function render_content() {?> <label> <span class="customize-control-title"><?php echo esc_html( $this->label );?></span> <textarea class="large-text" cols="20" rows="5" <?php $this->link(); ?>> <?php echo esc_textarea( $this->value() ); ?> </textarea> </label> <?php } } } $wp_customize->add_setting( 'site_intro', array( 'default' => '', 'transport' => 'postMessage' )); $wp_customize->add_section( 'theme_site_info', array( 'title' => 'Footer informaation', 'theme', 'description' => 'Custom Footer', 'theme', 'priority' => 20, )); $wp_customize->add_control( new PTD_Textarea_Control( $wp_customize, 'site_intro_control', array( 'label' => 'Website Footer', 'theme', 'section' => 'theme_site_info', 'settings' => 'site_intro' ))); } add_action( 'customize_register', 'theme_customize_register' );
最佳答案
您可以使用get_theme_mod
函数的第二个参数。您可以传递默认值作为第二个参数,如果您的设置之前尚未保存,该参数将被返回。
<p><?php echo get_theme_mod('site_intro', 'Copyright '.date('Y'));
关于php - WordPress 定制器 - 替换 get_theme_mod 中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23069067/