問題描述
每當我在 WordPress 發佈頁面中發佈一些內容時,它會顯示一些段落標籤,如<p> 和<br/> 。這顯示了一些額外的輸出空間。那有什麼解決辦法嗎?如何刪除所有標籤?
最佳解決方案
這是因為 WordPress 的 wpautop 。只需在主題的 functions.php 文件中添加下面的代碼行即可
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
欲瞭解更多信息:http://codex.wordpress.org/Function_Reference/wpautop
次佳解決方案
我不建議使用 remove_filter 選項,因為它會刪除您在模板中調用它們的標籤和標記。
最好的方法是通過 PHP 清理你的字符串
您可以使用 php 函數 strip_tags 來刪除無用的標記:echo strip_tags(get_the_excerpt()); // Get the raw text excerpt from the current post
要麼
echo strip_tags(category_description()); // Get the raw text cat desc from the current cat page
這將刪除當前 wordpress 帖子中的所有 HTML 標籤。
您也可以在以下情況下添加修剪功能:echo trim(strip_tags(get_the_excerpt())); // Get the raw text excerpt from the current post
要麼
echo trim(strip_tags(category_description())); // Get the raw text cat desc from the current cat page
這是完美的獲取元的原始文本= “description” 和標題,其中 HTML 標記不推薦。
希望有幫助
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。