You’re registering the option in the customizer as an option
and then trying to get it as a theme_mod
. If you simply change the type
from option
to theme_mod
when you’re registering the setting it’s gonna work fine. So try using this code:
add_action('customize_register', 'h2c_customize_register');
function h2c_customize_register($wp_customize) {
$wp_customize->add_setting(
'logo_width_px', array (
'default' => '',
'capability' => 'edit_theme_options',
'type' => 'option',
'transport' => 'postMessage',
)
);
$wp_customize->add_control(
'logo_width_px', array(
'label' => __('Logo Width', 'obf_text'),
'section' => 'h2c_default_things',
'settings' => 'logo_width_px',
)
);
}
and then to get the option this:
echo get_theme_mod( 'logo_width_px' );
Please note in the code above I used logo_width_px
instead of h2c[logo_width_px]
That’s because theme_mods are serialized options anyway, you don’t need to do anything more.