Discussion:
Excerpt output
Dino Termini
2014-06-11 13:07:09 UTC
Permalink
Hi,

my website uses shortcodes to define the structure of each page (Visual
Composer). Since I don't use excerpts, search results display the
content generated by those shortcodes. Is there a way to tweak
the_excerpt so that all but one shortcode are stripped from the output?

Example:

[vc_row][vc_column width="1/4" el_class="sidebar"]sidebar content
here[/vc_column][vc_column width="3/4"][vc_column_text
el_class="use-as-excerpt"]main content[/vc_column_text][/vc_column][/vc_row]

When the excerpt is displayed, it should return just what's inside the
vc_column_text shortcode: main content.

When inspecting the content passed to the function by add_filter(
'the_excerpt', 'strip_shortcodes' ), 100 ) , I see the shortcodes have
already been executed :/

Thanks,
Dino.
Nicholas Ciske
2014-06-11 15:10:47 UTC
Permalink
A filter running at priority 100 is going to run after anything in core (which generally defaults to 10, but not always)... and anything added with the default priority (10).

Find where your theme or plugin adds do_shortcode to the_excerpt filter and hook in earlier (e.g. priority 5).

Keep in mind that strip_shortcodes removes all shortcodes and their content. You'll probably need a regex to strip out everything but the shortcode you want -- then let the do_shortcodes filter do it's job up the stack.

Related and possibly useful:

Stripping shortcodes, keeping the content
http://wordpress.org/support/topic/stripping-shortcodes-keeping-the-content

_________________________
Nick Ciske
http://thoughtrefinery.com/
@nciske
Is there a way to tweak the_excerpt so that all but one shortcode are stripped from the output?
[vc_row][vc_column width="1/4" el_class="sidebar"]sidebar content here[/vc_column][vc_column width="3/4"][vc_column_text el_class="use-as-excerpt"]main content[/vc_column_text][/vc_column][/vc_row]
When the excerpt is displayed, it should return just what's inside the vc_column_text shortcode: main content.
When inspecting the content passed to the function by add_filter( 'the_excerpt', 'strip_shortcodes' ), 100 ) , I see the shortcodes have already been executed :/
Loading...