We try applying an altered version of this (very popular) code in a custom-functions plugin. It was even mentioned at stackoverflow but the whole question was deleted since the user asking was removed. Here is a Google cached version. Closely modified code is still present.
This is the altered code:
// Add Character Counter to the Excerpt Meta Box
function excerpt_count_js(){
if ('page' != get_post_type()) {
echo '<script>jQuery(document).ready(function(){
jQuery("#postexcerpt .handlediv").after("<div style=\"position:absolute;top:5px;right:80px;color:#666;\"><small>Excerpt length: </small><input type=\"text\" value=\"0\" maxlength=\"3\" size=\"3\" id=\"excerpt_counter\" readonly=\"\" style=\"background:#fff;\"> <small>character(s). (128 Characters MAX)</small></div>");
jQuery("#excerpt_counter").val(jQuery("#excerpt").val().length);
jQuery("#excerpt").keyup( function() {
jQuery("#excerpt_counter").val(jQuery("#excerpt").val().length);
if ( jQuery("#excerpt_counter").val() >= 129 ) {
jQuery("#excerpt_counter").css("color","red");
} else {
jQuery("#excerpt_counter").css("color","green");
}
});
});</script>';
}
}
add_action( 'admin_head-post.php', 'excerpt_count_js');
add_action( 'admin_head-post-new.php', 'excerpt_count_js');
It works well on the excerpt meta box, producing expected results.
But it causes multiple issues on the Edit Media
screen. Although it is coded to load only if ('page' != get_post_type())
and on admin_head-post.php
or admin_head-post-new.php
.
These issues are:
- the
Help
andScreen Options
buttons become un-clickable. - the
Hover Effect
does not work on the admin sidebar - the
Description buttons
(like b+i+img etc.) just disappear.
We have tried the original as well as other modified versions of the script with no luck.
Similar questions have been asked here and here seemingly using the same jQuery coding. Still, no one has reported any issues. Is it just us?
EDIT:
Since you asked, the errors are:
Uncaught TypeError: Cannot read property 'length' of undefined
Uncaught TypeError: Cannot read property 'hasClass' of undefined