2012-02-23 47 views
2

我試圖剝離默認情況下爲the_excerpt()放置的標籤;WordPress刪除摘錄篩選器

我試過下面...

<?php remove_filter('the_excerpt', 'wpautop'); ?> 
<p class='test'><?php the_excerpt(); ?></p> 

,我已經試過......

<?php $formatted = remove_all_filters('the_excerpt', the_excerpt()); ?> 
<p class='test'><?php echo $formatted ?></p> 

我期待產生這樣......

<p class='test'>the excerpt text <a href='http://continuereadinglink'>etc.</a></p> 

但是相反的WordPress輸出這...

<p class='test'></p> 
<p class='default-align'>the excerpt text <a href='http://continuereadinglink'>etc.</a></p> 

其實我已經找到了解決辦法在這裏http://aaronrussell.co.uk/legacy/improving-wordpress-the_excerpt/,但它主要涉及更換摘錄功能,我寧願避免這種情況,因爲我只是想剝離過濾掉。

回答

3

HTML段落標記不支持嵌套結構。嘗試以環繞摘錄與塊元素,如DIV

你可以試試這個選項:

<p class="test"><?php echo strip_tags(get_the_excerpt()) ?></p> 
+0

啊是啊,當然,我應該已經意識到這點。雖然通過刪除過濾器,但仍希望剝離「default-align」類。 – SparrwHawk 2012-02-23 11:21:24

+0

嘗試<?php remove_filter('the_excerpt','default-align'); ?> – seferov 2012-02-23 11:26:51

+0

沒有:-( 我試圖 ''' '

SparrwHawk 2012-02-23 11:40:05