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...
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 );
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: