php - Add characters counter to wordpress title and excerpt -


i want create counter @ bottom of fields post title , post excerpt, when user exceed limit, should alert ("you put more characters recommended!"), can decide ignore alert , keep typing.

didn't find solution in web match requirements.

open functions.php file in theme’s directory , paste @ end code below:

<?php function my_title_count(){ ?> <script>jquery(document).ready(function(){ jquery("#titlediv .inside").after("<div style=\"position:absolute;top:40px;right:-5px;\"><span>max 70 characters:</span> <input type=\"text\" value=\"0\" maxlength=\"3\" size=\"3\" id=\"title_counter\" readonly=\"\" style=\"background:none;border:none;box-shadow:none;font-weight:bold; text-align:right;\"></div>"); jquery("#title_counter").val(jquery("#title").val().length); jquery("#title").keyup( function() { jquery("#title_counter").val(jquery("#title").val().length); }); }); </script> <? } add_action( 'admin_head-post.php', 'my_title_count'); add_action( 'admin_head-post-new.php', 'my_title_count'); ?>  <?php function my_excerpt_count(){ ?> <script>jquery(document).ready(function(){ jquery("#postexcerpt .handlediv").after("<div style=\"position:absolute;top:4px;right:25px;\"><span>max 156 characters:</span> <input type=\"text\" value=\"0\" maxlength=\"3\" size=\"3\" id=\"excerpt_counter\" readonly=\"\" style=\"background:none;border:none;box-shadow:none;font-weight:bold; text-align:right;\"></div>"); jquery("#excerpt_counter").val(jquery("#excerpt").val().length); jquery("#excerpt").keyup( function() { jquery("#excerpt_counter").val(jquery("#excerpt").val().length); }); }); </script> <? } add_action( 'admin_head-post.php', 'my_excerpt_count'); add_action( 'admin_head-post-new.php', 'my_excerpt_count'); ?> 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -