• I want to ensure that when WP shows an excerpt created with the ‘more’ quicktag, that it does not auto-truncate before or after my placed ‘more’ quicktag. I’m finding that WP will auto-truncate posts even where I have set a ‘more’ quicktag IF they go over the word limit that I set with a mod in the theme.

    Full-text homepage posts show fine, as do posts under the truncate word limit. I just want WP to check for the <more> tag before truncating.

    I believe that this is a template function, but I’m not informed enough to parse the loop! I would certainly appreciate any pointers….

Viewing 1 replies (of 1 total)
  • in function.php(template)

    /* truncate
    **************************************************************/
    function truncate($str, $len=80, $etc='') {
        $end = array(' ', '.', ',', ';', ':', '!', '?');
    
        if (strlen($str) <= $len)
            return $str;
    
        if (!in_array($str{$len - 1}, $end) && !in_array($str{$len}, $end))
            while (--$len && !in_array($str{$len - 1}, $end));
    
        echo rtrim(substr($str, 0, $len)).$etc;
    }

    in template page
    <a href="<?php the_permalink(); ?>"><?php truncate(get_the_content(), 90, ' {...}'); ?></a>

Viewing 1 replies (of 1 total)
  • The topic ‘Hacking – no truncating when shortcode is used’ is closed to new replies.