Okay
  Public Ticket #1017595
Truncating blog post titles
Closed

Comments

  •  2
    Gidsey started the conversation

    Hi,

    I would like to be able to truncate the blog post titles (on the main blog page) so that they each appear as no more than 30 characters followed by an ellipsis ('...').

    Is there a way to achieve this, perhaps by adding a function to the functions.php file?

    Many thanks,

    Chris

  •  1,558
    Laborator replied

    Hi Chris,

    Can you try out this code, paste it in your functions.php file:

    function truncate_the_title_blog( $title ) {
        if ( is_archive() || is_home() ) {
            $chars = 30;
            
            if ( strlen( $title ) > $chars ) {
                return substr( $title, 0, $chars ) . '...';
            }
        }
        
        return $title;
    }
    add_filter( 'the_title', 'truncate_the_title_blog' );

    Best regards,
    Laborator Team


      Documentation         Join Kalium Users Group

  •  2
    Gidsey replied

    That works a treat, thanks Art!

  •  1,558
    Laborator replied

    Glad to hear that GIdsey

    Best regards,
    Laborator Team


      Documentation         Join Kalium Users Group