Archived topic
truncate title too long
1 reply · Started by anand on March 16, 2020
Viewing posts 1–2 of 2
how to cut titles which are too long, say more than 60 characters and append ... trailing to that title
Hi there,
it means filtering the_title function, which is a bit of a pain as that function can be used in more places then just the post title. But you can try this PHP snippet:
function archive_title_length( $title ) {
$max = 60;
if( strlen( $title ) > $max && !is_admin() && !is_single() ) {
return substr( $title, 0, $max ). " …";
} else {
return $title;
}
}
add_filter( 'the_title', 'archive_title_length');
This should only apply to frontend archives.
This archived topic is closed to new replies.