• Been going around this for a few hours without luck.
    Is there a way to offset the starting word or character when you get the_excerpt?

    I’m having an issue with a plugin that inserts social sharing references at the start of every post i.e. “Tweet Share Email” (see here) and I’d like to strip it from the excerpt.

    The length of the added text is always the same so either stripping the first word or the first ‘n’ characters from the beginning would work.

    I’ve found many posts about limiting the excerpt at it’s end but none for doing it at it’s beginning so any clue would be appreciated, thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • You could create a filter on the_excerpt and remove the text.

    This filter assumes that a leading p tag precedes the text you want to strip:

    // Filter to strip content from front of excerpt
    function mm_strip_excerpt($excerpt) {
       $text_to_strip = 'product'; // The text to strip
       $excerpt = preg_replace("/^<p>$text_to_strip/",'<p>',$excerpt);
       return $excerpt;
    }
    add_filter('the_excerpt', 'mm_strip_excerpt');
    Thread Starter Borbotron

    (@computacion)

    Hey, I’ve just seen this suggestion.

    I’ve tried it and some variants but without luck, thanks anyway!

    Thread Starter Borbotron

    (@computacion)

    OK, I found one that works!

    <?php
    $myExcerpt = get_the_excerpt();
    $tags = array(“”);
    $myExcerpt = str_replace($tags, “”, $myExcerpt);
    echo $myExcerpt;
    ?>

    Hope it helps someone else too, cheers!

    Hi Computacion

    I also need to change the excerpt starting point and it looks like you’ve found a way to do it. Could you please let me know in which specific file and where exactly I would use the above code. I’m new to PHP.

    Thanks

    Thread Starter Borbotron

    (@computacion)

    Hi clegg100,

    What that code does is to remove a string of text from the_excerpt, it doesn’t change the starting point (which was my original question, I know), sorry!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Change excerpt starting point (the_excerpt offset?)’ is closed to new replies.