2

Edit: It's working now, please lock the thread.

I am using the Understrap framework (Underscores plus Bootstrap).

$wp_customize->add_section( 'understrap_theme_post_options', array(
    'title'       => __( 'Theme Post & Archive Settings', 'understrap' ),
    'capability'  => 'edit_theme_options',
    'description' => __( 'Post and Archive Settings', 'understrap' ),
    'priority'    => 160,
) );

$wp_customize->add_setting( 'understrap_show_updated_post', array(
    'default'           => 'no',
    'type'              => 'theme_mod',
    'sanitize_callback' => 'understrap_theme_slug_sanitize_select',
    'capability'        => 'edit_theme_options',
) );

$wp_customize->add_control( new WP_Customize_Control(
    $wp_customize,
    'understrap_show_updated_post_cn', array(
        'label'    => __( 'Show Last Updated Date', 'understrap' ),
        'section'  => 'understrap_theme_post_options',
        'settings' =>  'understrap_show_updated_post',
        'type'     => 'select',
        'choices'  => array(
            'yes'      => __( 'Yes', 'understrap' ),
            'no'       => __( 'No', 'understrap' ),
        ),
        'priority'    => '10',
    )
) );

I have added this code in Customizer.php

Everything works fine, values are being saved because when I refresh the Customizer, I can see the updated value. However, when I do this on template-tags.php, it does not output anything:

echo get_theme_mod( 'understrap_show_updated_post' );

What am I doing wrong?

  • You'll need JS to accompany the PHP. Read this, especially Parts 2 & 3 on css & live-update: codex.wordpress.org/Theme_Customization_API & here's another relavent link: developer.wordpress.org/themes/customize-api/… – admcfajn Mar 26 '18 at 4:44
  • Don't I need JS only for auto updating the theme while customizing? I believe it should work even without JS after publishing, or am I wrong? – Rohan Sharma Mar 26 '18 at 5:20
  • Sorry, I thought you said after publishing it was good. Have you tried get_option('understrap_show_updated_post') instead of get_theme_mod? – admcfajn Mar 26 '18 at 5:56
  • Yes, I tried both, did not work. – Rohan Sharma Mar 26 '18 at 6:05
  • Where in template tags have you put that code? In a template tag function? Or just at the bottom? Does it work if you place it directly in a template? – Jacob Peattie Mar 26 '18 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.