Hi,
I want to limit the ‘description’ field output so I can create a summary on one page and get the full description on another. I know where to place my code, I’m just not sure how to limit the character output of my ‘description’ field.
I have this;
<?php the_field('description'); ?>
Lets say I want to limit the output to 20 words, how can I do that easily?
Thanks
Danny
Hi @danfloun @smspaul
Exactly! And make sure to use get_field
instead of the_field
to get the value, and then pass it into the function to trim it down.
Cheers
E
Okay, this is what I did;
<?php $summary = get_field('description');
echo substr($summary, 0, 200); ?>
That does what I require, thanks.
I would recommend using the built in WP function wp_trim_words
.
<?php $excerpt = wp_trim_words( get_field('your_custom_field' ), $num_words = 50, $more = '...' ); ?>
https://codex.wordpress.org/Function_Reference/wp_trim_words
Thanks @lukeclifton, this works really great and is simple.
Hello,
Thank you for solving that. But where should I place this code please ?
its worked perfectly
Thanks