2015-10-14 37 views
1

这个问题背后的想法是获取用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()返回完整的帖子内容,包括简码。使用strip_shortcodes()也会删除短代码之间的内容。

那么我的计划是使用模式去除短码?并修剪消息以模仿摘录功能。 PS:这pattern不起作用。

+0

https://wordpress.org/support/topic/stripping-shortcodes-keeping-the-content#post-2770209 – rnevius

回答

7

使用这个表达式:

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