Limit wordpress title to 25 characters

Limit wordpress title to 25 characters

To limit a WordPress post title to 25 characters, you can use the wp_trim_words or mb_strimwidth function in PHP. A simple and effective way is:

<?php
$title = get_the_title();
$short_title = mb_strimwidth($title, 0, 25, '...');
echo esc_html($short_title);
?>
This ensures that if the title exceeds 25 characters, it is neatly trimmed and appended with an ellipsis (...), maintaining readability without breaking the layout.