WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

    $permaLength = strlen(the_title());
<h2 class="<?php if ($permaLength > 68) {echo 'smaller';} ?>">
    <a href="<?php the_permalink() ?>">
        <?php the_title(); ?>

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?

share|improve this question
Don’t use strlen(), use mb_strlen() instead. – toscho Oct 26 '12 at 12:26
'but it seems that' - it would take less than 5 minutes to find out for sure, by searching the Codex; codex.wordpress.org/Function_Reference/the_title – Michael Oct 26 '12 at 12:41
up vote 1 down vote accepted

the_title() echoes the result. Use get_the_title() to return the title.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.