Advertisement
GochiSiyan

subtitle counter

Apr 28th, 2022
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. /* COUNT TITLE CHARACTER
  2. --------------------------------------------------*/
  3. function lvdny_title_count()
  4. {
  5. $screen = get_current_screen();
  6. if( $screen->post_type != "post")
  7. return;
  8.  
  9. echo '<script>'
  10. . 'jQuery(document).ready(function()'
  11. . '{'
  12. . 'jQuery("#titlewrap").append("<div id=\"lvdny_alert_char_title\"></div>");'
  13. . 'jQuery("#title").keyup( function()'
  14. . '{'
  15. . 'lvdny_update_lenght_title();'
  16. . '});'
  17. . 'function lvdny_update_lenght_title() {'
  18. . 'var lvdny_char_count = jQuery("#title").val().length;'
  19. . 'jQuery("#lvdny_alert_char_title").text("Caratteri usati: " + lvdny_char_count + " – di 55");'
  20. . 'if( lvdny_char_count > 55 ) {'
  21. . 'if( !jQuery("#lvdny_alert_char_title").hasClass("lvdny_alert_char_max") ) {'
  22. . 'jQuery("#lvdny_alert_char_title").addClass("lvdny_alert_char_max");'
  23. . '}'
  24. . '} else {'
  25. . 'if( jQuery("#lvdny_alert_char_title").hasClass("lvdny_alert_char_max") ) {'
  26. . 'jQuery("#lvdny_alert_char_title").removeClass("lvdny_alert_char_max");'
  27. . '}'
  28. . '}'
  29. . '};'
  30. . 'lvdny_update_lenght_title();'
  31. . '});'
  32. . '</script>'
  33. . '<style>'
  34. . '#lvdny_alert_char_title{ padding-bottom:10px; text-align: right; }'
  35. . '</style>';
  36. }
  37. add_action( 'admin_footer-post.php', 'lvdny_title_count');
  38. add_action( 'admin_footer-post-new.php', 'lvdny_title_count');
  39.  
  40.  
  41. /* COUNT SUBTITLE CHARACTER
  42. --------------------------------------------------*/
  43. function lvdny_subtitle_count()
  44. {
  45. $screen = get_current_screen();
  46. if( $screen->post_type != "post")
  47. return;
  48.  
  49. echo '<script>'
  50. . 'jQuery(document).ready(function()'
  51. . '{'
  52. . 'jQuery("#jnews_post_subtitle").append("<div id=\"lvdny_alert_char_subtitle\"></div>");'
  53. . 'jQuery("#jnews_post_subtitle>input").keyup( function()'
  54. . '{'
  55. . 'lvdny_update_lenght_subtitle();'
  56. . '});'
  57. . 'function lvdny_update_lenght_subtitle() {'
  58. . 'var lvdny_char_count = jQuery("#jnews_post_subtitle>input").val().length;'
  59. . 'jQuery("#lvdny_alert_char_subtitle").text("Caratteri usati: " + lvdny_char_count + " – di 80");'
  60. . 'if( lvdny_char_count > 80 ) {'
  61. . 'if( !jQuery("#lvdny_alert_char_subtitle").hasClass("lvdny_alert_char_max") ) {'
  62. . 'jQuery("#lvdny_alert_char_subtitle").addClass("lvdny_alert_char_max");'
  63. . '}'
  64. . '} else {'
  65. . 'if( jQuery("#lvdny_alert_char_subtitle").hasClass("lvdny_alert_char_max") ) {'
  66. . 'jQuery("#lvdny_alert_char_subtitle").removeClass("lvdny_alert_char_max");'
  67. . '}'
  68. . '}'
  69. . '};'
  70. . 'lvdny_update_lenght_subtitle();'
  71. . '});'
  72. . '</script>'
  73. . '<style>'
  74. . '.pxl_sottotitolo .acf-label{ position:relative }'
  75. . '#lvdny_alert_char_subtitle{ position:absolute; right: 0px; top:0px; }'
  76. . '</style>';
  77. }
  78. add_action( 'admin_footer-post.php', 'lvdny_subtitle_count');
  79. add_action( 'admin_footer-post-new.php', 'lvdny_subtitle_count');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement