去除简码,保留中间内容

Strip shortcode, keep content in between

这个问题背后的想法在于获取使用 avada 创建的 post 的摘录,但我无法从 post 内容中删除短代码以显示 [=24] 的摘录=].

这是我的 post 示例(使用 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]`

默认值 the_excerpt(); 由于短代码而不起作用。 get_content() returns 完整的 post 内容,包括简码。使用 strip_shortcodes() 还会删除短代码之间的内容。

所以我的计划是使用模式去除简码?和 trim 模仿摘录功能的消息。 PS:这个不行。

使用这个正则表达式:

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

值得一提的是,您可以使用文本编辑器(例如 Notepad++ 或 EditPad Pro)使用此正则表达式来执行相同的操作:\[/?[^/\]]+/?\]

这将匹配所有简码,然后您可以替换为任何内容或 space,随便什么。