Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[WordPress] How to use the WordPress Theme Customizer, JavaScript, and `get_theme_mod` in order to toggle the visibility of an element.
wp.customize( 'acme_display_element', function( value ) {
value.bind( function( to ) {
if ( true === to ) {
$( '#element' ).removeClass( 'hidden' );
} else {
$( '#element' ).addClass( 'hidden' );
}
});
});
<?php $visibility = ( '1' == get_theme_mod( 'acme_display_element' ) ) ? 'hidden' : '' ?>
<div id="element" class="<?php echo $visibility; ?>">
<img src="acme.png" alt="Acme Image" />
</div><!-- #avatar -->
<?php if ( '1' == get_theme_mod( 'acme_display_element' ) ) { ?>
<div id="element">
<img src="acme.png" alt="Acme Image" />
</div><!-- #element -->
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.