I have this shortcode:
add_shortcode('refer', function($atts, $text)
{
$defaults = ['link' => '', 'nofollow' => true];
$atts = shortcode_atts($defaults, $atts, 'refer' );
$nofollow = $atts['nofollow'] ? 'rel="nofollow"' : 'external';
return sprintf('<a href="%s" %s>%s</a>', esc_url($atts['link']), $nofollow, $text);
});
with demo post content:
[refer link="http://www.lipsum.com"]Lorem Ipsum[/refer] is simply dummy text of the printing and typesetting industry. [refer link="http://www.lipsum.com"]Lorem Ipsum[/refer] has been the standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing [refer link="http://www.lipsum.com"]Lorem Ipsum[/refer] passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
The loop to echo out the excerpt:
while ( have_posts() ) : the_post();
the_excerpt();
endwhile;
The result:
is simply dummy text of the printing and typesetting industry. has been the standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. […]
Notice that all Lorem Ipsum
words were stripped from the excerpt.
After looking over the_excerpt() and other related functions, I found out the problem was caused by strip_shortcodes() inside wp_trim_excerpt function.
But because of strip_shortcodes()
has no filters, how can I change its behavior?