2017-08-16 74 views
0

我想用get_the_excerpt()帶來一些結果。如何從內容結果wordpress中刪除標籤?

在某些方面,我有這樣的結果。我想刪除這些標籤,結果

這是文字,我得到:

板球世界盃得主的板球世界盃冠軍:一個信息圖形由團隊AsiaBet.org嵌入板球世界盃獲勝者在您的網站:複製並粘貼下面的代碼https://www.asiabet.org/wp-content/uploads/2015/02/CWC_ALL1.jpg「alt =」板球世界盃獲勝者 - Asiabet.org「> https: //www.asiabet.org/cricket-world-cup-infographic/"> Asiabet.org 2015年板球世界盃獲勝者僅意味着一件事 - 國際商會板球世界...

我的代碼

$result = get_the_excerpt(); 

if ($result != '') { 
    echo $result . '...'.'<br><br>'; 
} else { 
    $post_id = get_the_ID(); 
    echo get_post_field('description', $post_id); 
} ?> 
+0

use:$ result = strip_tags(get_the_excerpt()); –

+1

'strip_tags()'? http://php.net/manual/en/function.strip-tags.php – JustBaron

+0

這是我的第一個行爲,但不知何故它沒有工作 –

回答

0
preg_replace('/\\[.*.\\]/', '', 'Cricket World Cup Winners [Info-graphic] [hupso] Cricket World Cup Winners : An info-graphic by the team at AsiaBet.org Embed Cricket World Cup Winners on Your Site: Copy and Paste the Code Below Cricket World Cup Winners by Asiabet.org 2015 only means one thing – the ICC Cricket', -1, $count); 
0

可以使用strip_shortcodes($結果);

+0

也沒有爲我的情況工作。謝謝! –

0

您可以使用下列內容: -

$result= strip_tags(get_the_excerpt()); 
$find = array('/\\[.*.\\]/', '/[a-zA-Z]*[:\/\/]*[A-Za-z0-9\-_]+\.+[A-Za-z0-9\.\/%&=\?\-_]+/i','[」]','[alt=Cricket World Cup Winners – >>]'); 
$result = preg_replace($find, '',$result, -1, $count); 

if ($result != '') { 
    echo $result . '...'.'<br><br>'; 
} else { 
$post_id = get_the_ID(); 
    echo get_post_field('description', $post_id); 
} 
+0

謝謝它僅刪除[信息圖] [hupso]。那麼我也應該使用正則表達式來處理圖片標籤嗎? –

+0

是否要刪除圖片標籤? –

+0

對不起,我看到我的帖子不對。檢查它是否再次需要 –

0

要刪除任何簡碼像[Info-graphic]。你必須定義這個簡碼在你的主題,否則它將作爲字符串行動,你可以使用任何PHP函數,即str_replace()函數 您可以通過以下給出添加簡碼替換此:

function shortcode_function($atts) { 
    return "1234567890"; 
} 
add_shortcode('Info-graphic', 'shortcode_function'); 

$result = 'this is shortcode [Info-graphic]'; 
strip_shortcodes($result); 

,此功能會工作。