2

I want this because:

1-) I have a list item ol /ol at the start of my every post.

2-) When wordpress shows summary of the post it reads some words from the beginning of the post.

3-) This causes the summary to be comprised of the navigation list of the post. The words from inside the ol /ol tags.

4-) I don't want the words from ol tags in my excerpt. I want it to directly go beyond the /ol tags for the excerpt content.

My code is:

function custom_excerpt($text) {
    $pos = strpos($text, '</ol>');
    $text = substr($text, $pos);
    return $text;
}
add_filter('the_excerpt', 'custom_excerpt');

This doesn't work. I guess the tags are already stripped so "strpos" can't find anything. But even i return "..." from function, the same text as before stays. Like my custom function has no effect. Why is that? Is the theme's functions somehow interferes with the excerpt code?

1
  • Do you need to use the_excerpt() or can you modify the theme code? Reason is, the_excerpt() strips out all html (as you have said) so ideally we write a function/filter against get_the_content() instead.
    – cowgill
    Commented Sep 14, 2016 at 1:19

1 Answer 1

-1

The easiest way is to use strip_tags().

// Remove all html from the excerpt.
function custom_excerpt( $text ) {
    return strip_tags( $text );
}
add_filter( 'the_excerpt', 'custom_excerpt' );

If you want to get fancy and trim the excerpt length, you can use this function.

// Trim default excerpt length from 55 chars to 20. 
function custom_excerpt_length( $length ) {
    return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 99 );
3
  • Please explain why the down vote.....
    – cowgill
    Commented Sep 13, 2016 at 4:57
  • i didn't give you downvote but,i don't want to strip tags. I want to strip what is inside the '<ol>' tags. But even i return "..." the same text appear as before. Like this filter has no effect. Commented Sep 13, 2016 at 9:26
  • @user1002601 Ok, you have since edited your question so it's more clear. I will update my response as well based on that.
    – cowgill
    Commented Sep 14, 2016 at 1:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.