最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme development - How do i make a custom section's setting display the default value in Customizer?

programmeradmin4浏览0评论

Have made a custom section that displays in the Customizer. It has controls for image upload and text inputs for both the heading and its link. I want to be able to show a default heading and link inside the inputs, before users enter their own content. Have added 'default' to both setting and get_theme_mod, but can't get it to show.

Here is heading and link input settings and controls, along with image of customizer showing no defaults inside the input controls:

// Add section, settings and controls for sids (sids stands for Single Item Display Section)

// Add the section for sids
$wp_customize->add_section( 'ccshoes_sids_section' , array(
    'title' => __( 'Single Item Display Section', 'ccshoes' ),
    'description' => __( '2 column section for displaying single item and text' ),

) );

 // Add the setting for sids heading text
$wp_customize->add_setting( 'ccshoes_sids_text_input', array (
    'default' => __( 'NEW ARRIVALS', 'ccshoes' ),
    'sanitize_callback' => 'sanitize_text'

));

// Add the control for sids heading text
$wp_customize->add_control( new WP_Customize_Control(
    $wp_customize,
    'ccshoes_sids_text_input_control',
    array( 
        'label' => __( 'Enter your heading, e.g: NEW ARRIVALS', 'ccshoes' ),
        'section' => 'ccshoes_sids_section',
        'settings' => 'ccshoes_sids_text_input',

)));

// Add the setting for sids heading/image link
$wp_customize->add_setting( 'ccshoes_sids_link_input', array (
    'default' => __( '/product-category/new-arrivals/', 'ccshoes' )
));

// Add the control for sids heading/image link
$wp_customize->add_control( new WP_Customize_Control(
    $wp_customize,
    'ccshoes_sids_link_input_control',
    array( 
        'label' => __( 'Enter your heading/image link', 'ccshoes' ),
        'section' => 'ccshoes_sids_section',
        'settings' => 'ccshoes_sids_link_input'

)));

// Output sids
function ccshoes_display_sids() {

$sids_image = get_theme_mod( 'ccshoes_sids_img_upload' );
$sids_heading = get_theme_mod( 'ccshoes_sids_text_input', 'NEW ARRIVALS' );
$sids_link = get_theme_mod( 'ccshoes_sids_link_input', '/product-category/new-arrivals/');

    // Output sids ?>
    <div class="row">
        <div class="col-1">           
            <a href="<?php echo $sids_link; ?>"><h1><?php echo $sids_heading; ?></h1></a>
        </div>
        <div class="col-2">
        <a href="<?php echo $sids_link; ?>"><img src="<?php echo $sids_image; ?>"></a> 
        </div>
    </div>
<?php }

add_action( 'ccshoes_sids_section', 'ccshoes_display_sids' );

发布评论

评论列表(0)

  1. 暂无评论