Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter streetlight708

    (@streetlight708)

    The code actually is:

    <a href="<?php the_permalink(); ?>"> <?php echo substr(get_the_title(), 0, 35); if(strlen(get_the_title()) > 20) echo ' ...'; ?></a>

    Sorry!

    Try re-posting your code – using the code button this time. It’s totally managed in your original post.

    Thread Starter streetlight708

    (@streetlight708)

    here it is again! Sorry, I put the code brackets in wrong.

    <a href="<?php the_permalink(); ?>"> <?php echo substr(get_the_title(), 0, 35); if(strlen(get_the_title()) > 20) echo ' ...'; ?></a>

    You can try:

    $the_title = get_the_title();
    if ( mb_strlen( $the_title, 'utf8' ) > 35 ) {
       $last_space = strrpos( substr( $the_title, 0, 35 ), ' ' ); // find the last space within 35 characters
       $the_title = substr( $the_title, 0, $last_space ) . '...';
    }
    <a href="<?php the_permalink(); ?>"><?php echo $the_title; ?></a>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Limiting Characters without cutting a word in half’ is closed to new replies.