Truncate post_title text in Recent Posts
-
Hello,
I have searched far and wide in the WP Support Forums for a solution to my issue, but I have yet to find one. Hopefully someone can help.
I am using the following code to display a list of recent posts in a specific location on my site:
<?php $recent_posts = wp_get_recent_posts(); foreach( $recent_posts as $recent ){ echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a> </li> '; } ?>
The list of posts displays fine, but what I would like to do is give the post_title a character limit, i.e. a post with the title “Really really really really long title” would display as “Really really…”, or whatever the character limit is.
Anyhow, I have found ways to truncate or limit the character limit of the_title and get_the_title across the entire site, but I just cannot seem to find a way to truncate the “post_title” in this specific piece of code.
Any help would be greatly appreciated.
Thanks.
- The topic ‘Truncate post_title text in Recent Posts’ is closed to new replies.