0

Please review this!

I used the solution on the suggested/solved topic you guys marked as double but it didn't work.

I want to shorten my WordPress article/post titles to a max nr of characters of 65.

i'm using this code:

    function custom_trim_my_title( $title ) {

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

The idea is that this code cuts the words in half and i don't want that.

What can i do?

ps: i know you this is kinda of a duplicate but, i've tried everything and it didn't work.

Thanks in Advance!

Regards.

legacy.so
  • 35
  • 8
  • @AlexShesterov Yes, i have seen that post but i've been trying to adapt all day long and i haven't achieved anything. That's why i decided to make a new post. :( – legacy.so Feb 16 '18 at 15:44
  • I tried my solution and it looks ok for me, the $end value change according to the first space after the 64th position and didn't cut word...try it maybe and tell me if it works? – Mickaël Leger Feb 16 '18 at 16:09
  • @MickaelLeger as i said i tried but it didn't work, but anyway i appreciate that you took some of your time to help me! :) – legacy.so Feb 17 '18 at 07:06
  • Ok, I tried it with some text in my $text var and it looks ok when I change the sentence ! I deleted my anwser if it didn't work and the question is maked as duplicated ! Hope you find the solution :) – Mickaël Leger Feb 19 '18 at 08:22

0 Answers0