fbpx
How to Add a Custom WordPress Post Title Truncate Length

How to Add a Custom WordPress Post Title Truncate Length

This snippet will allow you to define a custom truncate length of the WordPress post title in your template files.

Instructions
Add this to your functions.php file.

function cptl_title($char) {
     $title = get_the_title($post->ID);
     $title = substr($title,0,$char);
     echo $title;
}

And then add this to your template file where you want the post title to be displayed.

<?php cptl_title(100); ?>
*note – the number 100 is the characters allowed before title is being truncated. You can define any differently character amount on each post title thru-out your templates.

WordPress Snippet Info

Tested with Wordpress v. 4.9.5
Last Modified: 15.05.2018
Last Reviewed: 15.05.2018
Review Status: Needs Review

How to Add a Custom WordPress Post Title Truncate Length
3.5 (70.91%) 11 vote[s]
Please report broken snippets.
Report Broken Snippet

Recent Comments