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

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条)

报告相同问题?