Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. /*
  2. * Limit Category to 1 Category in Edit Screen.
  3. */
  4.  
  5. function limit_cat_to_one() {
  6. if ( is_admin() ) {
  7. ?>
  8. <script>
  9. jQuery( document ).ready( function ( $ ) {
  10. $( "#category-all input:checkbox" ).change( function () {
  11. var max = 1;
  12. var count = $( "#category-all input:checked" ).length;
  13. if ( count > max ) {
  14. $( this ).prop( "checked", "" );
  15. alert( "You can choose " + max + " Categor" + (
  16. max == 1 ? "y" : "ies"
  17. ) );
  18. }
  19. } );
  20. } );
  21. </script>
  22. <?php
  23.  
  24. }
  25. }
  26. add_action( 'admin_head', 'limit_cat_to_one' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement