That was actually a question by a fellow WordPress designer/developer when he realize his code didn’t work (I’ll explain the mistake below) It’s actually a simple mistake and can be avoided if we use “refresh” transport method when creating customizer option. But I do understand that “postMessage” transport method is better (but need more code).
So here’s a little example. I create a twentyfifteen child theme with customizer setting to hide/show header.
With very little code we can create that setting:
/* Customize Register */
add_action( 'customize_register', 'my_customize_reg' );
/**
* Create Customizer Setting
*/
function my_customize_reg( $wp_customize ){
/* Setting */
$wp_customize->add_setting( 'hide_header', array(
'default' => 0,
));
/* Control */
$wp_customize->add_control( 'hide_header', array(
'label' => 'Hide Header (masthead)',
'section' => 'title_tagline',
'settings' => 'hide_header',
'type' => 'checkbox',
'priority' => 40,
));
}
and we need to modify/override “header.php” template from child theme. We simply need to wrap the #masthead element with this code: #wordpress #smallbusiness #entrepreneur
https://managewp.org/articles/11551/how-to-use-customize-api-postmessage-method-to-hide-show-element
No comments:
Post a Comment