Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Created September 7, 2012 19:03
Show Gist options
  • Select an option

  • Save wpsmith/3668649 to your computer and use it in GitHub Desktop.

Select an option

Save wpsmith/3668649 to your computer and use it in GitHub Desktop.
Hides meta box based on page template selected.
/*
* Meta Box Admin Script
*
* @author Travis Smith
* @version 1.0.0
*/
/*
* Hides meta box based on page template selected.
*
* @param string metabox_name Meta Box Selector ID
* @param string page_template_file Template File
*/
function wps_hide_mb( metabox_name, page_template_file ) {
'use strict';
var metabox = jQuery('#'+metabox_name);
var page_template = jQuery('#page_template');
page_template.change(function() {
if ( page_template_file == jQuery(this).val() ) {
metabox.show();
jQuery('#'+metabox_name+'-hide').attr("checked", "checked");
} else {
metabox.hide();
jQuery('#'+metabox_name+'-hide').removeAttr("checked");
}
}).change();
}
jQuery(document).ready( function() {
wps_hide_mb( 'wps_portfolio_box', 'page_portfolio.php' );
wps_hide_mb( 'wps_services_box', 'page_services.php' );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment