• Hi, everyone,
    I have this function set in functions.php

    function titluscurt($text) { 
      $chars_limit = 80;
      $chars_text = strlen($text);
      $text = $text." ";
      $text = substr($text,0,$chars_limit);
      $text = substr($text,0,strrpos($text,' '));
    
      if ($chars_text > $chars_limit)
         { $text = $text. "..."; }
         return $text;
    }

    It’s function that shortens the title and ads ... at the end of shortened title.
    It worked perfectly fine until update to WordPress 6.0. Now it shortens the titles but not adding the ... at the end, with one exception, if I have in the title a comma (,). Does anyone have any ideea why and how to fix this? Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Unfortunately, you can’t see where the function is used. A filter, an action? Or from your theme?

    Did you also change the PHP version together with the WP update?

    Thread Starter adrian.alex

    (@adrianalex)

    It’s used in content.php in my custom theme, for defining how get_the_title is handled

    theme_post_wrapper(array('title' => '<a href="' . get_permalink($post->ID) . '" rel="bookmark" title="' . strip_tags(get_the_title()) . '">' . titluscurt(get_the_title()) . '</a>',));

    Tested this once and it doesn’t happen for me. I tested it with PHP 7.4 and 8.0 in WordPress 6.0. So this must have another cause with you. My advice would be to debug the individual steps, with var_dump() output each where which variable has which value. Then you should be able to find the cause.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Function for title not working properly’ is closed to new replies.