2015-10-14 53 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);