0

i recently started creating my wordpress blog, and i would like to limit the title of a post to 2 rows to keep everything organized. I already found a function that lets a limit in amount of characters, but that doesn't solve the problem on all devices and their different screen sizes. So does anybody know if its even possible to limit the post title to 2 rows in the blog layout using CSS/PHP? thanks

this is what i found:

add_filter( 'the_title', 'max_title_length' );
function max_title_length( $title ) {
    $max = 20;
    if( is_home() && strlen( $title ) > $max ) {
        $title = substr( $title, 0, $max ) . " …";
    }
    return $title;
}
1
  • You would have to write a condition within that max_title_length function. If(wp_is_mobile()){ do something..} else { do something different. Above that, I think you are running into a dead end, since you can't know all device widths of all devices, it is going to be screwed up at some point, or you'd spend an incredible amount of time, catching all device widths. You should consider another design approach in my opinion. – user3135691 Feb 23 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.