php - WordPress 定制器 - 替换 get_theme_mod 中的文本

标签 php wordpress

我在 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/

相关文章:

wordpress - Cloudflare » 图像丢失并出现 404 错误,仅在 Chrome 上

php - 如何获取带有偏移量和限制的predis数据?

php - 获取邮件应用程序以识别回复电子邮件 php

php - 连接 MySQL 表并计算计数 - PHP 中的输出

php - wordpress 网站上有时出现间歇性服务器错误

php - 如何在 sql 查询 VALUES 中包含分号?

php - MySQL 计数功能无法正常工作

PHP、MySQL、PDO 事务 - 调用 commit() 后是否可以使用 rollBack()?

php - 导出到 csv wordpress

php - 检查自定义字段