The first thing to do is to create the function. Open your functions.php file and paste this code:
function ODD_title($char) {
$title = get_the_title($post->ID);
$title = substr($title,0,$char);
echo $title;
}
Now, you can use the function on your theme files. Just pass how many characters you want to display as a parameter. In the following exemple, only the first 20 chars of the title will be displayed:
<?php ODD_title(20); ?>
Thanks to Orange Dev Design for the tip!
Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!
Easily display post titles with a custom length