php - Why does character trim work for get_the_excerpt and not for the_excerpt?
Get the solution ↓↓↓So I am wishing to trim the excerpt for a specific loop and it was all working fine until I imported a load of posts for that category loop. Now the excerpt trim is not working and only seems to work if I use $excerpt = get_the_excerpt();
Any ideas?
<?php $excerpt = the_excerpt(array ( 'class' => 'custom-excerpt'));
echo substr( $excerpt, 0, 100); ?>
Answer
Solution:
returns the text so you can capture it and modify the contents.
outputs the content so it is echo'd out and you are not actually receiving the text.
If you have to usethe_excerpt()
you can use output buffering to capture the output and then massage the data as necessary:
ob_start();
the_excerpt(array ( 'class' => 'custom-excerpt'));
$excerpt = ob_get_clean();
$excerpt = substr( $excerpt, 0, 100);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: npm err! code 1
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.