I searched for "title length" in questions but results were all about setting max length and limiting and..
What I want to do is to create an if-statement, to determine if the post title has more than 68 characters or not and if it had, add smaller
class to it.
I wrote the code like this:
<?php
$permaLength = strlen(the_title());
?>
<h2 class="<?php if ($permaLength > 68) {echo 'smaller';} ?>">
<a href="<?php the_permalink() ?>">
<?php the_title(); ?>
</a>
</h2>
but it seems that the_title()
function is not returning the value and instead it's echoing out. Is there an alternative way to fetch the title length?
strlen()
, usemb_strlen()
instead.