Spacing within the excerpt

The excerpt stips all html tags, a feature that frustrates many. I have written a custom excerpt that stops the excerpt from stipping any html tags. It also breaks the excerpt after the sentence after the set amount of words. If you need to cut the excerpt at exact words, you will just need to … Read more

Stripping shortcode from custom excerpt function

Don’t use a custom function. You should use the hooks. You don’t have to strip shortcodes, wordpress does that for you automatically, just use something like this // setting higher priority so that wordpress default filter have already applied add_filter(‘the_excerpt’, ‘custom_excerpt_filter’, 11); function custom_excerpt_filter($excerpt) { // apply your logic of read more link here return … Read more

Excerpts that don’t truncate words

Set the filter dynamically based on the page you are loading. If category archive pages have a 100 word excerpt, but posts have a 10 word excerpt, and everything else uses the default: function my_custom_excerpt_length( $orig ) { if( is_category() ) { return 100; } elseif( is_single() ) { return 10; } return $orig; } … Read more

Cannot strip JW Player shortcode?

JW Player Plugin for WordPress does not register its shortcode like all other shortcodes, so strip_shortcodes() will not know about it and not strip it. In the code there is a note that this is because it uses argument names with a . in it, and WordPress does not support this. There are probably multiple … Read more

When is wp_trim_excerpt() called?

If you’ve already looked in XRef, you’ve seen this comment at the top of the doc block: /** * Generates an excerpt from the content, if needed. So it’s not used in core, but is available for you to use if you need it. Update Let me explain a little of what’s going on: excerpt_length … Read more

Shortcode content does not show in feed discription/excerpt

Ok I had to write my own custom excerpt like such: function custom_excerpt($text=””) { $raw_excerpt = $text; if ( ” == $text ) { $text = get_the_content(”); // $text = strip_shortcodes( $text ); $text = do_shortcode( $text ); $text = apply_filters(‘the_content’, $text); $text = str_replace(‘]]>’, ‘]]>’, $text); $excerpt_length = apply_filters(‘excerpt_length’, 200); $excerpt_more = apply_filters(‘excerpt_more’, ‘ … Read more

How to show only manual / custom excerpts?

You can use has_excerpt() for this, which checks whether the post has a manually set excerpt. The sample code below uses this function: <?php if ( has_excerpt() ) : // Only show custom excerpts not autoexcerpts ?> <span class=”entry-subtitle”><?php echo get_the_excerpt(); ?></span> <?php endif; ?>

Show Video in Excerpt

filtering the_excerpt() If you remove_filter( ‘get_the_excerpt’, ‘wp_trim_excerpt’ ) and add your own get_the_excerpt filter you can do this. The default filter (wp_trim_excerpt()) can be found on line 2023 of /wp-includes/formatting.php if you want to just modify that. The extent of what you need to do is just modifying which tags are allowed in strip_tags(). overriding … Read more

add_filter on “the_excerpt” only works when post does not have excerpt

I posted an article about this a while ago: function wp_trim_all_excerpt($text) { // Creates an excerpt if needed; and shortens the manual excerpt as well global $post; $raw_excerpt = $text; if ( ” == $text ) { $text = get_the_content(”); $text = strip_shortcodes( $text ); $text = apply_filters(‘the_content’, $text); $text = str_replace(‘]]>’, ‘]]&gt;’, $text); } … Read more