Created
April 10, 2019 17:38
-
-
Save Asikur22/f8cc0b5657c14319b75fcac1d4c1b1c6 to your computer and use it in GitHub Desktop.
[Limit Category to 1 Category in WordPress Edit Screen] #Taxonomy
This file contains hidden or 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
/* | |
* 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