如何仅删除页面的自动段落格式,而不删除帖子(WordPress) [英] How do I remove auto paragraph formatting for pages ONLY, and not posts (WordPress)
问题描述
我已经很熟悉在WordPress中删除自动段落格式的小技巧:
I'm familiar with this little trick already for removing auto paragraph formatting in WordPress:
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
...但是,将其添加到 functions.php 中会删除整个网站的段落.这不是我想要的,因为客户需要能够自己进行编辑(段落格式确实可以帮助他们在帖子中进行操作).
...however adding this in functions.php removes paragraphs for the entire site. This is not what I want since the client needs to be able to make edits themselves (the paragraph formatting really helps them out on posts).
在客户的主页上有JavaScript片段的情况下,自动段落插入特别容易受到破坏.因此,理想情况下,我想仅对此页面或所有 pages 禁用自动p格式设置,并在必要时保留所有帖子.
Where the auto paragraph insertions are particularly damaging is on the client's home page, where there are javascript snippets. So ideally, I would like to disable auto p formatting for this page alone, or all pages if necessary, and leave posts alone.
有什么想法吗?如果需要,我可以提供更多信息.
Any ideas? I can provide more information if needed.
提前谢谢!
我尝试过的插件:Php Exec,Raw HTML,禁用WordPress Autop,PS禁用自动格式化,切换wpautop
Plugins I've tried: Php Exec, Raw HTML, Disable WordPress Autop, PS Disable Auto Formatting, Toggle wpautop
推荐答案
You should be able to check if the template being rendered is a page using is_page(), and then optionally run the filter. We hook into 'wp_head'
, so that we can run the check before the_content
is called.
示例:
function remove_p_on_pages() {
if ( is_page() ) {
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
}
}
add_action( 'wp_head', 'remove_p_on_pages' );
这篇关于如何仅删除页面的自动段落格式,而不删除帖子(WordPress)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!