Created
April 16, 2014 13:20
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wp.customize( 'acme_display_element', function( value ) { | |
value.bind( function( to ) { | |
if ( true === to ) { | |
$( '#element' ).removeClass( 'hidden' ); | |
} else { | |
$( '#element' ).addClass( 'hidden' ); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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