A Bit of Character Counting Stupidity

When I’m using WordPress’ Status Post Format, I like to keep it to 140 characters, so it’s like a Tweet. But how many characters have I typed? Cos The Visual Editor only shows Word Count. So I took a look around and saw various ways of doing it, quite a few using regex to strip ‘unwanted characters’—but a space counts as a character! So I wrote my own, based loosely on what I’d been using for counting characters in the Excerpt, and from a few different plugins and bits of code. Turned out to be surprisingly easy and uncomplicated (I say that now, of course).

So, first I need a function to call a couple of files if I happen to be editing a Post or Page:

function supernaut_character_count( $charcount ) {
  if ( 'post.php' == $charcount || 'post-new.php' == $charcount ) {
    wp_enqueue_style( 'character-count-css', get_stylesheet_directory_uri() . '/css/char-count.css', array() );
    wp_enqueue_script( 'character-count-js', get_stylesheet_directory_uri() . '/js/char-count.js', array( 'jquery' ), '20160519', true );
  else return;
add_action( 'admin_enqueue_scripts', 'supernaut_character_count' );

Then I slap together some jQuery:

jQuery( document ).ready( function( $ ) {
  if( $( '.post-php' ).length || $( '.post-new-php' ).length ) {
    $( '#post-formats-select input' ).click( function() {
      if ( $('#post-format-status').is(':checked') ) {
        $( '#post-status-info tr:first-child' ).after( 'Character count: 

‘ ); $( ‘#content_ifr’ ).ready( function () { setInterval( function() { var tinymcebody = $( ‘#content_ifr’ ).contents().find( ‘body’ ); $( ‘#postdivrich .character-count’ ).html( tinymcebody.text().length ); }, 500 ) }); } else { $( ‘#post-status-info tr:first-child’ ).nextAll().remove(); } }); } });

Then a miniscule bit of CSS:

.post-php #wp-character-count {
  font-size: 12px;
  line-height: 1;
  display: block;
  padding: 0 10px 4px;

It’s a little bodgy, and if I had more than the 45 minutes to a) work out how the Visual Editor can be fiddled with, and b) write something that worked and looked ok—the bare minimum really—I’d do it slightly nice and maybe consider for a minute throwing it into a plugin (where it officially belongs). But I won’t. It does what I want: live updating of how many characters I’ve written in the Visual Editor, and shows it in a line underneath the Word Count (also aided me in delaying writing a residency application on the day it’s due).

comments are open … -ish

Does it look like I’m avoiding doing real work today, with a monster funding application due on Monday, what do I do? Muck around with Movable Type’s atrociously obtuse templates and horrendous css, all to try and get comments not just working, but looking ok-ish when they get published.

So, comments are open.

Still a bit of formatting weirdness going on, but I’ll start opening up old posts over the coming week once I’ve cleaned up the skankiness. The comments preview page is unformatted, and more importantly you have to wait for me to approve, so things don’t appear all by magic when you hit ‘post’. I’ll work on that too, but need an umbrella from spam.

just some blabbing about coding

During my rather pitiful self-help attempt at getting comments working, that quite possibly soon will be after a couple of people pointed out what I was missing, I also discovered I could easily fix a couple of the bugs hanging over from when I redid the site to this hell-vetica version.

So, the search page is finally formatted. OMG!!!

Actually this is just a test for the return of comments. Obviously I don’t have enough going on with three applications due tomorrow and another on Monday.

Ho hum … waiting for Movable Type to rebuild 1039 entries. Considering changing to WordPress in the meantime … idly wondering if I could do a full WP install and rewrite all the templates to this version of supernaut in the time it takes MT to rebuild … start to get excited/worried when I realise it could make a fun afternoon game this weekend.

Anyway for now, comments are semi-working. In that they show up and get published, but they take a while to appear on the site for you to read. Boringness. Adding some more code in … rebuilding … yawn …

Blahing around with css…

Comments are more-or-less working. (Which is to say, whatever isn’t working, I don’t know about.)

Only open on this post for now. And I closed them cos this is really a test post, not a vehicle for your self-aggrandizement.

Much formatting to be done…

Sleep and smutty dreams first though.

a bit of a test

I spent the morning upgrading my blog software to Movable Type 3.34, possibly a stupid move but it seemed like a good idea at the time. So I guess the absence or presence of this post will unequivocally indicate the success of said venture, and let me know just how much of staring-at-code I’ll be doing in the coming days.

The search is kind of working again, but I can’t find the template so instead you get ugly Movable Type default I-have-no-style style. I’m going to change to a different search engine though, as the MT one is like a neanderthal bludgeoning a Louis XIV chair with a stone club. So, any weirdness is my fault, and seducing me with chocolate will assist the weirdness in going away sooner.

edit …

Mostly working. I’m also changing the search engine to Fast Search, but I am lazy and can’t imagine I’ll get it finished today. So … no search.