Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created April 16, 2014 13:20
Show Gist options
  • Save tommcfarlin/a5885f6e5950d901034b to your computer and use it in GitHub Desktop.
Save tommcfarlin/a5885f6e5950d901034b to your computer and use it in GitHub Desktop.
[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