Skip to content

Instantly share code, notes, and snippets.

@dannyockilson
Last active December 17, 2015 11:59
Show Gist options
  • Save dannyockilson/5605934 to your computer and use it in GitHub Desktop.
Save dannyockilson/5605934 to your computer and use it in GitHub Desktop.
Hide sections of options when using Wordpress Options Framework http://wptheming.com/options-framework-theme/
// In options.php
$options[] = array(
'name' => __('Example Hide', 'options_framework_theme'),
'desc' => __('Example Hide Multiple Fields', 'options_framework_theme'),
'id' => 'example_showhidden',
'type' => 'checkbox');
$options[] = array(
'name' => __('Example Hidden 1', 'options_framework_theme'),
'desc' => __('Example hidden field 1', 'options_framework_theme'),
'id' => 'example_property_id',
'std' => 'Default Value',
'class' => 'hidden',
'type' => 'text');
$options[] = array(
'name' => __('Example Hidden 2', 'options_framework_theme'),
'desc' => __('Example hidden field 2', 'options_framework_theme'),
'id' => 'example_domain_name',
'std' => 'Default Value',
'class' => 'hidden',
'type' => 'text');
// In functions.php
function optionsframework_custom_scripts() { ?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('[id*=showhidden]').click(function() {
if (jQuery(this).is(':checkbox')) {
var id = jQuery(this).attr('id');
var current = "section-"+id.replace("showhidden","");
jQuery('[id*='+current+']').each(function(){
if(jQuery(this).hasClass("hidden")){
jQuery(this).fadeToggle();
}
});
}
});
jQuery('[id*=showhidden]').each(function(){
if (jQuery(this).is(':checkbox') && jQuery(this).attr("checked")) {
var id = jQuery(this).attr('id');
var current = "section-"+id.replace("showhidden","");
jQuery('[id*='+current+']').show();
}
});
});
</script>
<?php }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment