剥离短代码,保持介于两者之间的内容

kri*_*ajb 4 wordpress strip shortcode

这个问题背后的想法在于摘录用avada创建的帖子,但我不能从帖子内容中删除短代码以显示帖子的摘录.

这是我的帖子的例子(使用avada):

[fullwidth background_color="" background_image="" class="" id=""]
[one_full last="yes" spacing="yes" class="" id=""][fusion_text]
Content text ...   
[/fusion_text][/one_full][/fullwidth]`
Run Code Online (Sandbox Code Playgroud)

the_excerpt();由于短代码,默认设置不起作用.get_content()返回完整的帖子内容,包括短代码.使用strip_shortcodes()还会删除短代码之间的内容.

所以我的计划是使用模式剥离短代码?并修剪消息以模仿摘录功能.PS:这种模式不起作用.

The*_*tor 12

使用这个正则表达式:

$excerpt = get_the_excerpt();
$excerpt = preg_replace("~(?:\[/?)[^/\]]+/?\]~s", '', $excerpt);
Run Code Online (Sandbox Code Playgroud)