WordPress.org

Forums

Network Latest Posts
[resolved] Excerpt length (2 posts)

  1. uros_m
    Member
    Posted 2 years ago #

    I can limit the excerpt length by words but how can I limit it by chars? If I input a bare number it limits it to words although I think I saw somewhere that a bare number should limit by character.

    So, how to limit the excerpt length by character count?

    Cheers,

    UroŇ°

    http://wordpress.org/extend/plugins/network-latest-posts/

  2. Jose Luis SAYAGO
    Member
    Plugin Author

    Posted 2 years ago #

    Hi,

    If you want to limit by chars you have to replace the nlp_custom_excerpt function from the file network-latest-posts.php on line 885 by this one:

    function nlp_custom_excerpt($count, $content, $permalink, $excerpt_trail){
        if($count == 0 || $count == 'null') { $count = 55; }
        /* Strip shortcodes
         * Due to an incompatibility issue between Visual Composer
         * and WordPress strip_shortcodes hook, I'm stripping
         * shortcodes using regex. (27-09-2012)
         *
         * $content = strip_tags(strip_shortcodes($content));
         *
         * replaced by
         *
         * $content = preg_replace("/\[(.*?)\]/i", '', $content);
         * $content = strip_tags($content);
         */
        $content = preg_replace("/\[(.*?)\]/i", '', $content);
        $content = strip_tags($content);
        // Limit the number of characters
        $content = substr($content, 0, $count);
        $content = $content . '...';
        // Add the trail
        switch( $excerpt_trail ) {
            // Text
            case 'text':
                $content = $content.'<a href="'.$permalink.'">'._('more').'</a>';
                break;
            // Image
            case 'image':
                $content = $content.'<a href="'.$permalink.'"><img src="'.plugins_url('/img/excerpt_trail.png', __FILE__) .'" alt="'._('more').'" title="'._('more').'" /></a>';
                break;
            // Text by default
            default:
                $content = $content.'<a href="'.$permalink.'">'._('more').'</a>';
                break;
        }
        // Return the excerpt
        return $content;
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Network Latest Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic