Right now i have an excerpt that outputs 82 words (ACF excerpt) from each of parent pages that i have.
I would like to output instead 400 characters from each page since right now one output have like 400+characters (82words) and another one have 500+characters (82words) and it looks really weird.
I have looked at stackoverflow and codex but not been able to find an solution.
functions.php
function tjanster_sida_excerpt($title) {
global $post;
$text = get_field($title);
if ( '' != $text ) {
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$excerpt_length = 82; // words
$excerpt_more = apply_filters('excerpt_more', ' ' . ' ');
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
}
return apply_filters('the_excerpt', $text);
}
my-template.php
<?php
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order'
);
$parent = new WP_Query( $args );
if ( $parent->have_posts() ) : ?>
<?php while ( $parent->have_posts() ) : $parent->the_post(); ?>
<article>
<header>
<?php the_title(); ?>
</header>
<?php
global $more;
$more = 0;
?>
<p><?php echo tjanster_sida_excerpt('redigerare'); ?></p>
<a href="<?php echo get_permalink(); ?>" class="btn btn-readmore">Read more</a>
</article>
<?php endwhile; ?>
<?php endif; wp_reset_query(); ?>
How do i trim it to 400 characters ?