• I wasn’t able to locate this on Google, so I was hoping that someone could help me here.

    I’m using the following code to customize the_excerpt output.

    function improved_trim_excerpt($text) {
            global $post;
            if ( '' == $text ) {
                    $text = get_the_content('');
                    $text = apply_filters('the_content', $text);
                    $text = str_replace('\]\]\>', ']]>', $text);
                    $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
                    $text = strip_tags($text, '<p> <em> <i> <b> <strong> <img>');
                    $excerpt_length = 50;
                    $words = explode(' ', $text, $excerpt_length + 1);
                    if (count($words)> $excerpt_length) {
                            array_pop($words);
                            array_push($words, 'read more...');
                            $text = implode(' ', $words);
                    }
            }
            return $text;
    }
    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    remove_action('wp_head', 'rel_canonical');
    add_filter('get_the_excerpt', 'improved_trim_excerpt');

    Obviously on the page I’m calling the file I just put in the_excerpt()

    What I’m wondering, would it be possible to make the_excerpt() a ‘conditional’ kind of tag? A few areas of the site that I’m working on require no “read more” information, where as other sections do. Is there a way to modify the actual call itself?

    For example:

    <?php the_excerpt('no-read-more');?>

Viewing 1 replies (of 1 total)
  • There are different ways you can achive this, most likely you’ll have to create a new variable that will save the setting:
    $noReadMore = 0 or $noReadMore = 1
    and then depending on this variable display or don’t display the content

Viewing 1 replies (of 1 total)
  • The topic ‘Customizing The_Excerpt’ is closed to new replies.