Limit the Title Length on Custom Post Type Archive Page to a Set Number of Characters

<?php echo substr(get_the_title(), 0,42) ;?>

Notice the echo and the get_the_title()

This will get you the result you’re looking for.


Here’s an alternative to consider:

I’ve always found character limits cause weird word breaks that users find confusing.

WordPress has a function called wp_trim_words that you can use.

<?php echo wp_trim_words( get_the_title(), 5, '...' ); ?>

5 – the number of words you want to show

‘…’ – the trail after the last word shown (so you could have ‘- cont.d’ or ‘…read more’ or something)