Skip to content

Instantly share code, notes, and snippets.

@Asikur22
Created April 10, 2019 17:38
Show Gist options
  • Save Asikur22/f8cc0b5657c14319b75fcac1d4c1b1c6 to your computer and use it in GitHub Desktop.
Save Asikur22/f8cc0b5657c14319b75fcac1d4c1b1c6 to your computer and use it in GitHub Desktop.
[Limit Category to 1 Category in WordPress Edit Screen] #Taxonomy
/*
* Limit Category to 1 Category in Edit Screen.
*/
function limit_cat_to_one() {
if ( is_admin() ) {
?>
<script>
jQuery( document ).ready( function ( $ ) {
$( "#category-all input:checkbox" ).change( function () {
var max = 1;
var count = $( "#category-all input:checked" ).length;
if ( count > max ) {
$( this ).prop( "checked", "" );
alert( "You can choose " + max + " Categor" + (
max == 1 ? "y" : "ies"
) );
}
} );
} );
</script>
<?php
}
}
add_action( 'admin_head', 'limit_cat_to_one' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment