I'm learning how you can shorten a title only when it's over 8 figures lengthy. If it's more than 8 figures, then echo the very first 8 figures and set an ellipse after it.

This is how I get the title:

<?php echo $post->post_title ?>

Any help could be greatly appreciated. This is an excellent learning lesson for me personally in order to replicate this later on, so again any help could be amazing.


    if (strlen($post->post_title) > 8)
       echo substr($post->post_title, 0, 8) . ' ...';
       echo $post->post_title;


Alternatively, if you possess the mbstring extension is enabled, gleam shorter way as recommended by Gordon's answer. When the post's encoding is multibyte, You'd want to use mbstring anyway, otherwise figures are counted improperly.

echo mb_strimwidth($post->title, 0, 8, ' ...');

You should use [cde]


If you wish to truncate regarding word limitations, see

You want to do this in wordpress plugin if you alter the theme the alterations is going to be lost

you can test this.

echo mb_strimwidth('Your Title', 0, 8, '…');

So right now you you don't need to change max char in most the road of code.