Trim $title on news widget


I am using Perth and really loving the theme. Congratulations to your team! My question is if you could please help me with a little push in the right direction. I am importing a facebook feed as posts and this works perfectly fine, but I want to trim the imported title. I managed to add a function to my child’s functions.php which seems to work, but it does only trim the title when the post is viewed via archive.php. Unfortunately not when the post is displayed via the news widget or in single post view. So my question is if you could tell me if in the widget/single post view uses something different then $title or subsitutes $title which is targeted by my function.

Thanks very much in advance, I know customization is not part of your support, but maybe if you could point me in some direction it might help others too.



the_title is used in the archives and also the single posts and news widget so if you’re not running any conditional checks that are true only for the archives, your function should work. Perhaps paste the function here, though as you’ve pointed out, we can’t help you with customizations, especially PHP ones.

Dear Vlad,

Thanks for replying so quickly. I am not a php expert, but there is no intentional conditional check that is running- maybe I just missed sth. The function I am using is

function custom_trim_my_title( $title ) {
	if ( strlen( $title ) >= 50 && ! is_singular() ) {
		$title = substr( $title, 0, 50 ) . '...';
		return $title;
	return $title;
add_filter( 'the_title', 'custom_trim_my_title' );


Maybe something jumps at you! Really appreciate your help! Thank you!

So yeah, you have a conditional that makes your code apply on everything but single posts/pages.
Please change your second line to this:

if ( strlen( $title ) >= 50 ) {

Dear Vlad! Ohhh…I totally missed that! Thank you very very much! You are a wizard!!