简体   繁体   English

Wordpress - 防止自动<p>在 TinyMce</p>

[英]Wordpress - prevent auto <p> in TinyMce

I am using ACF, and using TinyMCE Advanced plugin.我正在使用 ACF,并使用 TinyMCE 高级插件。

When editing posts, the editor inserts new links into p tags, which I am trying to prevent as I am using the code tag and if there is a return within the code within the code tag, it wraps it in a new p and code block that then breaks the layout of the post.编辑帖子时,编辑器将新链接插入到 p 标签中,我正在尝试阻止这种情况,因为我正在使用代码标签,如果代码标签内的代码中有返回,它会将其包装在新的 p 和代码块中然后破坏了帖子的布局。

I have tried playing with the plugin settings to check to remove the p tags, however no luck.我尝试使用插件设置来检查是否删除 p 标签,但是没有运气。

I have searched and found that I should be setting forced root block to false, however I am still unable to get it to work:我已经搜索并发现我应该将强制根块设置为 false,但是我仍然无法让它工作:

add_filter('tiny_mce_before_init', function ($init) {

        //Prevent <p> tags in editor
        $init['forced_root_block'] = false;
        $init['force_br_newlines'] = false;
        $init['force_p_newlines'] = false;
        $init['convert_newlines_to_brs'] = false;

        return $init;
    });

When viewing the post in Text tab, the code shows no P tags, however when editing within the visual tab, its breaking it all out into p tags.在文本选项卡中查看帖子时,代码不显示 P 标签,但是在可视选项卡中进行编辑时,会将其全部分解为 p 标签。

Any ideas on how to resolve?关于如何解决的任何想法?

When you output the content, while in a loop, you can sanitize the output to remove any and all tags using wp_strip_all_tags .当您 output 内容时,在循环中,您可以使用wp_strip_all_tags清理 output 以删除任何和所有标签。

Properly strip all HTML tags including script and style.正确剥离所有 HTML 标签,包括脚本和样式。

<?php wp_strip_all_tags( the_content(), true ); ?>

( true or false for line breaks). truefalse换行)。 Same thing for ACF, just englobe the output in it. ACF 也是如此,只需将 output 嵌入其中即可。

Alternatively, you can remove any auto <p> tag applied as line break by removing the wpautop via remove_filter in your function.php file.或者,您可以通过function.php文件中的remove_filter删除wpautop来删除作为换行符应用的任何自动<p>标记。

<?php remove_filter( 'the_content', 'wpautop' ); ?>

And with an ACF editor WYSIWYG/TinyMCE并使用 ACF 编辑器所见即所得/TinyMCE

<?php remove_filter ( 'acf_the_content', 'wpautop' ); ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM