Excerpt post wordpress

Asked

Viewed 98 times

0

What’s wrong? I did the function to excerpt in wordpress posts and import to another site, however it is not cutting with what I set.

Someone can give a light?

<?php while (have_posts()): the_post(); ?>
                    <div class="moldG">
                        <div class="thumbsG">
                            <?php the_post_thumbnail( array(300,266) ); ?>
                        </div>
                    </div>
                    <div class="wptexto">
                            <a class="blog" href="<?php the_permalink(); ?>" target="_blank"><?php the_title(); ?></a>
                            <?php the_excerpt(); 
                             if ( is_category() || is_archive() ) {
                                    the_excerpt();
                                    } 
                           function new_excerpt_length($length) {
                               return 240;
                               }
            endwhile; ?>
                    </div>  
                </div>
  • 1

    It’s not about your question, but you’re calling the_excerpt twice on the category and file page.

1 answer

2


This is not how this filter is used. First you should declare the function new_excerpt_length in the functions.php of your theme and then add as filter excerpt_length.

function new_excerpt_length($length) {
    return 240;
}
add_filter('excerpt_length', 'new_excerpt_length');

After that the summary size returned by the_excerpt() will be a maximum of 240 words throughout the site.

  • 1

    Thank you very much, I got.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.