PHP return size of WordPress Articles

I’m trying to make WordPress return the length of my articles in 3 categories: Small, Medium and Large.

I’m currently using this function to test it but I doesn’t seem to work (I’m a total PHP noob!)

Read More
function wcount(){
ob_start();
the_content();
$content = ob_get_clean();
    if ($content > 4000) {
        return 'large';
    } else if ($content > 2500) {
        return 'medium';
    } else {
        return 'small';
    }
}

Could anyone please help me? It would be even better if the function automatically added the post to the right category in WordPress, but for now this was all I could.

Thanks in advance!

Related posts

Leave a Reply

1 comment

  1. You can use the strlen function to get the length of a string:

    function wcount()
    {
        ob_start();
        the_content();
        $content = ob_get_clean();
        $length = strlen($content);
        if ($length > 4000) return 'large';
        if ($length > 2500) return 'medium';
        return 'small';
    }