0

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?

0

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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.