Important:
This support area is for Kalium 3 users only. Support for Kalium 4 has moved to our new platform at support.laborator.co. If you’re using Kalium 4, please create a new account there using your email and license key. A password will be sent to you automatically.

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,561
    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,561
    Laborator replied

    Glad to hear that GIdsey

    Best regards,
    Laborator Team


      Documentation         Join Kalium Users Group