• Does anyone know of a way, in your “previous” and “next” post links (like the default template has in the single.php) to, say, 20 characters?

    I have mine set up and rolling, but due to most of my post titles being loooooooooong, the links end up wrapping to the next line and screwing up my layout. I’d like to keep them on the same line, hopefully by truncating the title/link text.

    Help?

Viewing 2 replies - 1 through 2 (of 2 total)
  • I can imagine a very, very complicated method of doing this without editing the core source files, but let’s stick to the basics (as I’d rather not spend a few hours coding this up):

    In wp-includes/template-functions-links.php you’ll need to change two function, i.e. next_post and previous_post. In 1.5, you’ll find previous_post around line 300; next_post is the ‘next’ function after. Look for the following line in both:

    $string .= wptexturize($lastpost->post_title);

    (next_post will have $nextpost->post_title) Change it to this:

    $chars = strlen(utf8_decode($lastpost->post_title));
    $lastpost_title = substr(wptexturize($lastpost->post_title), 0, 20);
    if($chars > 20) {
    $lastpost_title .= '...';
    }
    $string .= wptexturize($lastpost_title);

    Make sure to change all $lastpost elements to $nextpost in the next_post function.

    Note: Back up source files before editing, and comment your changes for future reference.

    Thread Starter armageddondesign

    (@armageddondesign)

    Those initial strings don’t seem to be anywhere in that php file…and I even used Dreamweaver’s find function.

    Oh well. Thanks anyway.

    I think I’ll just tweak out a version of the links that puts the post title in the “title” attribute of the link, but leaves the visible links as “previous post” and “next post”.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Truncating Titles in Previous/Next Links?’ is closed to new replies.