douzhuican0041 2014-04-14 19:53
浏览 167
已采纳

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

I have footer in Wordpress theme, and in the footer paragraph.

It looks like this:

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

And when you in customizer there is option to change text in footer.
I want to be displayed by default for example:
Copyright 2014.

This is default text, and if user change this, text will be replace Copyright 2014 and it will be text that user has setup.

Where I need to make some code, in footer.php, functions.php where are the rest of the code for customizer?

Is this made with if else statement, or there is some premade code in Wordpress?

This is 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' );
  • 写回答

2条回答 默认 最新

  • dongyoulou4829 2015-01-17 13:08
    关注

    You can use the second parameter of get_theme_mod function. You can pass a default value as a second parameter, which will be returned, in case your setting has not been saved previously.

    <p><?php echo get_theme_mod('site_intro', 'Copyright '.date('Y'));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大