Wordpress tinyMCE Keep Wrapping <p> Tags To HTML Codes When Saving

Wordpress tinyMCE keep adding p tags when I saved my custom post types in visual mode opened!

I had searching for many solutions, but not working. Here is the solution that I found, but this is unable to stop wordpress from adding annoying p tags from my html codes:

Javascript:

script type="text/javascript"
     tinyMCE.init({force_p_newlines : false});
/script

PHP

function tinymce_remove_root_block_tag( $init ) {
    $init['wpautop'] = false; 
    $init['force_p_newlines'] = false; 
    $init['forced_root_block'] = false; 
    return $init;
}
add_filter( 'tiny_mce_before_init', 'tinymce_remove_root_block_tag' );

I don't want any kind of solution which is using the_content hook, because this is still letting p tags inside wordpress text editor. Example:

remove_filter ("the_content", "wpautop");

What else should I use to stop tinyMCE from messing up html codes with its auto added p tags?

Topic tinymce tags customization Wordpress

Category Web


I use this on my instals to get rid of p tags around images:

/*
*
* Remove annoying <p> tags on images, messes with my shizzle
*
*/


function my_filter_ptags_on_images($content)
{
    return preg_replace('/<p>(\s*)(<img .* \/>)(\s*)<\/p>/iU', '\2', $content);
}

add_filter('the_content', 'my_filter_ptags_on_images');

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.