Hi @schweizerschoggi,
You can use the wpp_excerpt_more filter hook to change the characters WPP appends to the end of the excerpt to what ever you want, like this for example:
/**
* Changes the ending string of the excerpt.
*
* @param string $more
* @return string
*/
function my_wpp_excerpt_more($more){
return '...';
}
add_filter('wpp_excerpt_more', 'my_wpp_excerpt_more', 10, 1);
However, wouldn’t it make more sense to simply reduce the length of the excerpt so that this line jump doesn’t happen?
In general I would agree. But I am displaying the excerpt (and additional information) on a tile so space might always be tight, even if I would reduce the excerpt to 10 or only 5 words.
Anyway.. I have added your snippet to the functions.php – but I don’t see any difference yet. Even if I change the return value to ‘***’ instead of ‘…’ – I just don’t see it.
PS, I am using it like this:
<span class="wpp-excerpt">{summary}</span>
Oh, it seems we have a bug in the plugin!
Try this:
1. Go to Plugins > Plugin Editor and select WordPress Popular Posts to edit it.
2. Click on src/Output.php to open this file.
3. Replace this (around line 548 I think):
$excerpt = Helper::truncate($excerpt, $this->public_options['post-excerpt']['length'], $this->public_options['post-excerpt']['words'], $this->more);
with this:
$more = apply_filters('wpp_excerpt_more', $this->more);
$excerpt = Helper::truncate($excerpt, $this->public_options['post-excerpt']['length'], $this->public_options['post-excerpt']['words'], $more);
4. Click on Update File to save changes.
Good morning Héctor!
Thank you for investigation and description.
Yes, now I can at least change the return value … to *** or whatever is needed.
Unfortunatly there is sill a space between the last word of the excerpt and the … so that it sometimes has the dots on a separate line.
Hi @schweizerschoggi,
Sorry for the super late reply.
Please update to version 5.4.0 as soon as you can. It includes the patch mentioned above and also makes sure to trim the excerpt before appending the “…” prefix at the end. This should fix the extra space that you’re seeing with some of your post excerpts.
Dear Héctor
Thank you for the notification!
I have updated to version 5.4.0 but unfortunatly I still see a space between the last character and the dots. No change here.
Do I have to change to code in the functions.php somehow?
/**
* Changes the ending string of the excerpt.
*
* @param string $more
* @return string
*/
function my_wpp_excerpt_more($more){
return '...';
}
add_filter('wpp_excerpt_more', 'my_wpp_excerpt_more', 10, 1);
Nope, that isn’t likely related to your issue.
I’m realizing right now that you must be truncating excerpts by word count and not by character count. That’s the only instance where WPP will add a space right before ‘…’ (see related code) which explains why the changes from the latest version didn’t remove it in your case 😛 I might need to tweak things a bit more.
Yes, that’s the case. We’re truncating after 20 words. 🙂
Alright, I’ll work on that on version 5.4.1. Should be out in a few days. For the time being you can delete the space from this line, that should do the trick.
Hey @schweizerschoggi,
The latest release removes the spacing for the truncated-by-words-count excerpt as well (from the referenced line of code that is, it’ll still display an empty space before the $more
characters by default unless you override it via filter hook).
Dear Héctor
Thank you for investing so much time on this issue… I really appreciate it!! (time for another coffee I guess 😉 )
I have just updated the plugin to v 5.4.1 and well … it works like a charm now! That’s really solving all my problems, my friend. And there is still the option to use it with or without the extra space (to be honest I’d prefer the space between the last word and the dots if not for the extra line from time to time).
So let me say a BIG THANK YOU once again – have a wonderful day, a good time and stay healthy!
Greetings from Switzerland
Schoggi