• Resolved SchweizerSchoggi

    (@schweizerschoggi)


    Dear Héctor

    Something special: I am displaying the excerpt of a post and the overflow ends with the usual three dots …

    Now if the space is tight it happens from time to time that the last word of the excerpt is in one line and the … remain all alone in the very next line.

    To avoid this I would like to ask you if it’s possible to remove the space between the excerpt and the dots.

    Thanks a lot (again!) in advance and have a wonderful day!
    Schoggi

    • This topic was modified 2 years, 8 months ago by SchweizerSchoggi. Reason: typo
Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    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?

    Thread Starter SchweizerSchoggi

    (@schweizerschoggi)

    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>

    Plugin Author Hector Cabrera

    (@hcabrera)

    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.

    Thread Starter SchweizerSchoggi

    (@schweizerschoggi)

    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.

    Plugin Author Hector Cabrera

    (@hcabrera)

    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.

    Thread Starter SchweizerSchoggi

    (@schweizerschoggi)

    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);
    Plugin Author Hector Cabrera

    (@hcabrera)

    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.

    Thread Starter SchweizerSchoggi

    (@schweizerschoggi)

    Yes, that’s the case. We’re truncating after 20 words. 🙂

    Plugin Author Hector Cabrera

    (@hcabrera)

    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.

    Plugin Author Hector Cabrera

    (@hcabrera)

    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).

    Thread Starter SchweizerSchoggi

    (@schweizerschoggi)

    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

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Excerpt: text to dots without space’ is closed to new replies.