0

I trying this directly in my theme:

$mods = $wp_customize->get_control('header_text'); if (isset($mods)) { echo 'YES'; } else { echo 'No'; } But nothing happened. and in debug.log : undefined variable wp_customize...

2 Answers 2

1

I'm not sure what exactly you're trying to accomplish, but if you're wanting to manipulate customizer controls until the customize_register action has fired. So do something like this:

add_action( 'customize_register', function( $wp_customize ) {
    $control = $wp_customize->get_control( 'header_text' );
    if ( $control ) {
        error_log( 'header_text control exists' );
    } else {
        error_log( 'header_text control does not exist' );
    }
}, 100 );
2
  • I just wanted to check and run a conditional to change something on the theme based on that. I'm not good with programming. Thank you! Your way is better! Feb 14, 2017 at 20:14
  • But mine also worked Feb 14, 2017 at 20:15
0

Use get_theme_mod and this work:

$mod = get_theme_mod('header_text'); if ( $mod != 0 ) { # code... echo 'YES'; } else { echo 'No'; } In this case I wanted to check if the Title and the slogam of the site was hidden or not.

To get the string> ID of the MOD is simply. inspect the option with the Customizer open, as show the image:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.