/*
* 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' );