Hi @max1138,
Thank you for your feedback, we’re happy to hear you like the plugin!
Regarding the snippet – I suspect the issue is related to the location where you load the snippet – if you use the “Run Everywhere” option some of the conditional logic is not available, please try using the “Site Wide Header” location so that the page-specific info is loaded.
We are working on a solution to avoid this issue in a future release.
Thanks
It still shows full title on main page even using that fix.
I’m sure it’s just me not understanding things correctly.
Hi @max1138,
Would it be possible to share the code of the snippet you are using to truncate the title so we can run some tests with different settings on our end?
Thanks
Sure thing:
function max_title_length( $title ) {
$max = 62;
if( strlen( $title ) > $max ) {
return substr( $title, 0, $max ). " …";
} else {
return $title;
}
}
add_filter( 'the_title', 'max_title_length');
Obviously, using it as a php snippet has the code as
<?php
function max_title_length( $title ) {
$max = 62;
if( strlen( $title ) > $max ) {
return substr( $title, 0, $max ). " …";
} else {
return $title;
}
}
add_filter( 'the_title', 'max_title_length');
I wanted to use this code below as wpbeginner say:
This method gives you more control over where your titles are shortened
But I wanted to see if the above worked first:
<a href="<?php the_permalink() ?>">
<?php
$thetitle = $post->post_title; /* or you can use get_the_title() */
$getlength = strlen($thetitle);
$thelength = 25;
echo substr($thetitle, 0, $thelength);
if ($getlength > $thelength) echo "...";
?>
</a>
Hi @max1138,
Thank you for the details.
I tried the snippet with the settings suggested above but 1 thing I had to adjust was the length limit. None of my titles reached 62 characters so none were getting cut off, I would suggest maybe trying something like 20 to make it more obvious when testing to find the perfect length for your layout.
The second thing I suggest is maybe combining 2 rules like this: https://a.supportally.com/i/MjaLUO
This should avoid a false positive when your homepage is set to a single page.
That worked a treat, thank you.
🙂