• 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

Viewing 10 replies - 1 through 10 (of 10 total)
  • 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.

    Thread Starter fabtigger

    (@fabtigger)

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

    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.

    Thread Starter fabtigger

    (@fabtigger)

    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).

    Thread Starter fabtigger

    (@fabtigger)

    Yeah, I had a try at those…

    Just had another try and this one works better than I originally realised
    https://www.ads-software.com/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

    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. ??

    Thread Starter fabtigger

    (@fabtigger)

    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

    @Raj

    (@rajeshtandonrocketmailcom)

    yep… it should work

    @Raj

    (@rajeshtandonrocketmailcom)

    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…

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How do I display a character count within a post?’ is closed to new replies.