WordPress.org

Ready to get started?Download WordPress

Forums

Character Counter WordPress (3 posts)

  1. Asif Mushtaq
    Member
    Posted 10 months ago #

    I am using this function in my function.php theme page.

    function bac_post_word_count(){
    global $post;
    //Variable: Additional characters which will be considered as a 'word'
    $char_list = ''; /** MODIFY IF YOU LIKE. Add characters inside the single quotes. **/
    //$char_list = '0123456789'; /** If you want to count numbers as 'words' **/
    //$char_list = '&@'; /** If you want count certain symbols as 'words' **/
    echo str_word_count(strip_tags($post->post_content), 0, $char_list);

    }

    Then i add this to show where i want in single.php or index.php

    <?php if(function_exists('bac_post_word_count')) { bac_post_word_count(); }?>

    But this just count the words not spaces, numeric, symbols etc....
    I want to count every type of characters, spaces, dots, commas, even everything please help me...

  2. linux4me2
    Member
    Posted 10 months ago #

    Can't you just use the PHP function strlen() instead of str_word_count()?

    You code would just be:

    function bac_post_word_count(){
    global $post;
    echo strlen(strip_tags($post->post_content));
    }
  3. Asif Mushtaq
    Member
    Posted 9 months ago #

    hmm nice thanks allot i solved.. .:) thanks again.. :)

Reply

You must log in to post.

About this Topic