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!)
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!
You can use the
strlen
function to get the length of a string: