Why we don’t have a Twitter characters counter.

Why there is no character counter for Twitter? Please add it, it should be easy.

It’s not that simple. Actually such counter is impossible to implement. Some parts of the message could be processed only after the blogpost is already published which makes it impossible to count characters at the time of writing.

Calculating number of characters for Twitter itself is not a problem. It’s it’s hard, it requires a very big JavaScript, but it’s possible.

The problem is in WordPress. WordPress is too powerful and has too many possibilities.

Here is an example.

Message format: %TITLE% – %URL% %CF-PRICE% %HTAGS% %HCATS% %HCT-PRDTAGS% – %EXCERPT%.

How to calculate number of characters?

Both %TITLE% and %EXCERPT% support HTML and shortcodes. There are also content filters that applied by WordPress and third party plugins. Some of those plugins apply their filters ONLY on the “view” action.

Example (title from the actual live website):

I just watched the movie “[movie-title-id-166]” – it was {great|awesome|hilarious|enjoyable}

How many characters here?

Once published this title could be:

I just watched the movie “The Imitation Game” – it was great‘ – 61 characters
I just watched the movie “The SpongeBob Movie: Sponge Out of Water” – it was awesome‘ – 68 characters

So how to get number of characters from %TITLE% and %EXCERPT%? You need to run a very extensive ajax call that will save the post draft and generate the view. People would want a “live” counter, so this ajax should be executed on each press of the button. That will degrade performance and still be slow. Oh and it could bring the wrong results, since it could save draft with “great” and publish the final post with “awesome”.

Next problem – WordPress does not save the tags along with draft. So we need a JavaScript that will scan tags. Even worse problem – custom taxonomies. We need a JavaScript that will analyze the DOM and find custom taxonomies in it.

And finally we came to the “impossible” part – %CF-PRICE%. This field is added by some plugin that has a very nice form for inserting the price of some custom product attached to the blogpost. There is no way to detect or parse this form since every plugin does it in it’s own unique way. This value can be obtained ONLY from the published post – there is no way to get it from the draft or from the interface.

Also let’s not forget custom post types. Those could have their own interface for everything including title and tags. How to get info from them?

The bottom line – the correct number of characters can be calculated only from the already published post. There is no way to get it on the fly.

© 2012-2016 NextScripts.com