WordPress.org

Ready to get started?Download WordPress

Forums

Word Count while entering new post in admin interface (6 posts)

  1. joelwalsh
    Member
    Posted 8 years ago #

    Any plugins or ideas for a script that can count the number of words typed into the text area in WordPress's admin screen for entering a post?

    I know there are JavaScripts for this for websites. Does WordPress's admin interface support JavaScript?

  2. Lorelle
    Member
    Posted 8 years ago #

    Do you want to see them on your admin panel or do you want the user to see this information on your post? If you want to know how many words you entered in the Write Post panel, well, that's something I've never heard of. If this is critical information for you, then I recommend that you write the post in a word processor (first turn off all the quote conversions) or find a good text editor with a word count and write your post in there and run it through the counter, then you would know. Then copy and paste it into WordPress. But MAKE SURE there are no curly quote marks and such as that will look weird on your blog.

    If you would like to have this information available for readers to see, then there are some plugins that might help. Also, on occassion, I've been able to activate plugins and put their php template tags in my admin panels and have that information appear there but not on my site, so you might try that, too, if you are brave and know what you are doing. I explain one example of how to do that here.

    Check out plugins that do this:

    http://codex.wordpress.org/Plugins/Statistics
    http://codex.wordpress.org/Plugins/Posts_Miscellaneous

  3. joelwalsh
    Member
    Posted 8 years ago #

    No, I was specifically asking for a word count in the admin interface of the post-writing area before it goes live.

    The "preview" of the post that you can get with several plugins includes date posted. Could it include the word oount as well, especially if you have a word count plugin that displays that on your posts?

    I am aware that Word has a word count feature, but I write an awful lot and every bit of time saved helps. Plus, as you've noted, copying and pasting from a word processor brings its own set of headaches.

    This is largely because I am using wordpress to write actual articles both for my own site(s) and for redistribution and not just a personal journal.

    But if more bloggers thought about writing quality issues such as word count, would that be such a bad thing?

  4. tsguitar
    Member
    Posted 8 years ago #

    I wanted this too, so here's what I did:

    I used to use Rodin as my blogging tool and that has taught me a lot over the last year and a half. Rodin counts words and I just took that code and put it into WordPress.

    I opened edit-form-advanced.php and found the beginning of the textarea where the post content is displayed. Here's what you are looking for:

    <?php the_quicktags(); ?>

    <div><textarea <?php if...

    Right after that DIV, paste this:


    <?php
    $post->post_content = preg_replace('/s+/', ' ', strip_tags($post->post_content)); // remove white space and html
    $words = ((count(explode(" ",$post->post_content)) + count(explode(".r",$post->post_content)))-1); // count spaces and periods
    if ($words == 1)
    {
    echo "<p class="note">Post length: ~ $words word
    ";
    }
    else
    {
    echo "<p class="note">Post length: ~ $words words
    ";
    }
    ?>

    I only use the advanced screen, but I'm sure this would work just fine in edit-form.php if you're using the visual rich editor. Open that file and search for textarea and you'll find the spot. Again, right after the DIV, paste the above code.

    Now, you just have to remember that you changed that file next time you upgrade. Anyone have an idea how to make this more streamlined?

  5. tsguitar
    Member
    Posted 8 years ago #

    Oops! That code will strip all blank spaces out of the post content and force you to deal with no line breaks in your entries. Here's the revised code:

    $countpost = $post->post_content;
    $countpost = preg_replace('/s+/', ' ', strip_tags($countpost)); // remove white space and html
    $words = ((count(explode(" ",$countpost)) + count(explode(".r",$countpost)))-1); // count spaces and periods
    if ($words == 1)
    {
    echo "<p class="note">Post length: ~ $words word
    ";
    }
    else
    {
    echo "<p class="note">Post length: ~ $words words
    ";
    }

    So far, the word count has been pretty close to the word count I get from Word. It counts things like the a in a href though. I'd like for it to not count anything within brackets so I get a true count of the words in each post minus any HTML I type in along the way. Suggestions?

  6. tsguitar
    Member
    Posted 8 years ago #

    The code pasted above is missing a few things because this forum parses them out. Copy from here instead:
    http://pastebin.ca/121545

Topic Closed

This topic has been closed to new replies.

About this Topic