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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog