remove the extra p tag in tinyMCE

给你一囗甜甜゛ 提交于 2019-12-20 11:59:15

问题


When you copy and paste from a word document in to the tinyMCE editor sometimes there are unwanted <p> tags:

<p>&nbsp;</p>
<div class="starpasspro-example-question">
   <p><strong>Example: Levels of strategy</strong></p>
   <p>Microsoft is one of the world&rsquo;s largest organisations, providing corporate solutions to businesses throughout the world to help them realise their fullest potential. At Microsoft, there are three levels of strategy as follows:</p>
</div>
<p>&nbsp;</p>

Here the code that generates I want to remove the <p> tags any way to do that ?


回答1:


Add these Lines in your tinymce.init({ });

Example:

tinymce.init({
    forced_root_block : "", 
    force_br_newlines : true,
    force_p_newlines : false,
});



回答2:


it will be helpful.

Add into your tinymce.yml file

forced_root_block : "" 

force_br_newlines : true

force_p_newlines : false



回答3:


Yes, this is possible. There is a secure way to remove all that html elements you want to removed (you may define what to keep). It is by using the tinymce config params paste_preprocess and a custom function strip_tags. Check it out here.




回答4:


Add this to your functions.php file and the standard p-tags tags will be removed by adding some parameters to the tiny_mce_before_init hook. If you want to see how it works, you can read further on this page: https://codex.wordpress.org/TinyMCE

////////////////////////////////////////////////////////////////////////
//////////REMOVE STANDARD <P> FROM TINYMCE EDITOR/////////////////////////
///////////////////////////////////////////////////////////////////////
function my_format_TinyMCE( $in ) {
$in['forced_root_block'] = "";
$in['force_br_newlines'] = TRUE;
$in['force_p_newlines'] = FALSE;
return $in;
}
add_filter( 'tiny_mce_before_init', 'my_format_TinyMCE' );


来源:https://stackoverflow.com/questions/17058644/remove-the-extra-p-tag-in-tinymce

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!