-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add limit characters on Wysiwyg #1
Comments
Hi @akididou Thanks for the question. Here's a thread discussing the tinymce JS to add a character count: And here's some documentation on how to customize the WYSIWYG field tinymce instance:
Good luck! |
hi I need to limit characters for a wysiwyg field .. can you please help with an example ? |
+1 i'd love an example of doing this |
Here is a solution for a little Word/Character Counter on the WYSIWYG Editor: Put this in your functions.php:
|
@fhauck many thanks for this, works really well. I have only noticed two things and made a few changes to the code to fix them and simplify it:
jQuery('#wp-'+id+'-editor-container .mce-statusbar').append('<div class="acfcounter" style="background-color: #f7f7f7; color: #444; padding: 2px 10px; font-size: 12px; border-top: 1px solid #e5e5e5;"><span class="words" style="font-size: 12px; padding-right: 30px;"></span><span class="chars" style="font-size: 12px;"></span></div>');
const counter = function() {
var value = jQuery('#'+id).val();
var wordCount = (value.length == 0) ? 0 : value.trim().replace(/\s+/gi, ' ').split(' ').length;
var totalChars = value.replace(/(<([^>]+)>)/ig,"").length;
jQuery('#wp-'+id+'-editor-container .mce-statusbar .acfcounter .words').html('Words: '+wordCount);
jQuery('#wp-'+id+'-editor-container .mce-statusbar .acfcounter .chars').html('Characters: '+totalChars);
};
counter();
jQuery('#'+id).change(counter);
jQuery('#'+id).keydown(counter);
jQuery('#'+id).keypress(counter);
jQuery('#'+id).keyup(counter);
jQuery('#'+id).blur(counter);
jQuery('#'+id).focus(counter); |
I ran into an error while running the code above. Here is an improved version of the code. Key Improvements:
|
Hi,
Is it possible to add a limit characters on Wysiwyg same as on the text area ?
So very nice job for this plugin ;)
Peace
The text was updated successfully, but these errors were encountered: