WordPress.org

Ready to get started?Download WordPress

Forums

How do I display a character count within a post? (11 posts)

  1. fabtigger
    Member
    Posted 2 years ago #

    I'm using the default twenty eleven template.

    I want to somehow display the amount of characters within a post. I would like to somehow automactically generate and append something like (this post contains 400 characters), it would also be great if I could also turn off this function as well.

    Any ideas on how I would go about this? Or perhaps a point in the right direction (i'm not very technical but will give anything a try)

    Thanks

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Do not edit the Twenty Eleven theme. It is the default WordPress 3.2 theme and having access to an unedited version of the theme is vital when dealing with a range of site issues.

    Create a child theme for your customisations. Once your child theme is active, we should be able to help with the customisation.

  3. fabtigger
    Member
    Posted 2 years ago #

    Sorry forgot to mention that my child theme is active, and I'm running the site from a local server. Sorry esmi

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    Is this for the front or back end of the site? Only running a character count on the front end of the site could have a significant performance impact on the site.

  5. fabtigger
    Member
    Posted 2 years ago #

    I would like for it to be displayed on the front-end. However, if it would increase performance, I would be statisfied with a character count in the back end which I could copy and paste into the post I guess? Would be nice if it were a button that you could press or tick (add character count to post).

  6. esmi
    Forum Moderator
    Posted 2 years ago #

    Have you had a look through these plugins: http://wordpress.org/extend/plugins/search.php?q=character+count

  7. fabtigger
    Member
    Posted 2 years ago #

    Yeah, I had a try at those...

    Just had another try and this one works better than I originally realised
    http://wordpress.org/extend/plugins/posts-character-count-admin/

    I thought that the character count only appeared in the 'view all posts' page, but it appears under the text box once the message has been saved.

    I suppose this will actually do, thanks for pointing me in the right direct esmi, I hope I didn't waste too much of you time x

  8. esmi
    Forum Moderator
    Posted 2 years ago #

    No problem. It's an interesting idea. I was about to see if I could come up with a basic coded solution to get you started when I thought I'd check through the Plugin Repo in case someone else had the same idea. :-)

  9. fabtigger
    Member
    Posted 2 years ago #

    Hey Esmi, admin plugin works well in the backend, but thought I'd try a better solution so that it workd in the frontend too. As i want to display the character count in the frontend, so the plugin available isn't the best. A friend made this plugin for me. It displays the characters used for each post.

    <?php
    
    //ADD FILTERS
    add_filter('the_content', 'char_count_func');
    function char_count_func($text)
    {
      $count = strlen($text);
      if(is_page())
        return $text;
      else
        return $text.'<br/><b>'.$count.' characters including spaces.</b>';
    }
    ?>

    The problem with it is that punction symbols and line breaks are counted as more than one character. Is there a way to adjust this to count all symbols and line breaks as 1 character. Also how would you restrict this from certain post?

    note: I found this code in another plugin which I think addreses the symbol count issue, but not the line break.

    function get_characters() {
    		if ($this->text == '') { return(0); }
    		if ($this->characters != -1) { return($this->characters); }
    
    		$count = strlen(utf8_decode($this->text));
    
    		$this->characters = $count;
    		return($count);
    	}

    Thanks

  10. @Raj
    Member
    Posted 1 year ago #

    yep... it should work

  11. @Raj
    Member
    Posted 1 year ago #

    how can i display post with 25 words only in my home page, as i want to show the full post text on other page with read more button???
    please guide...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags