Reputation: 1725
I am using WordPress editor TinyMCE. I have something like this:
<div class="TA_excellent" id="TA_excellent150"><ul>...</ul></div>
<script type="text/javascript" src="http://www.jscache.com/wejs?wtype=excellent&uniq=150&locationId=287500&lang=en_AU">
</script>
When I skipped to visual editor "script" tags are removed from the content. So I tried every kind plugin including Ultimate TinyMCE but this time "script" tags are wrapped by "p" tags.
So output is something like this:
...</ul></div>
<p>
<script type="text/javascript" src="http://www.jscache.com/wejs?wtype=excellent&uniq=150&locationId=287500&lang=en_AU">
</script>
<script src="http://www.tripadvisor.com.au/WidgetEmbed-excellent?uniq=150&locationId=287500&lang=en_AU"></script
</p>
I also tried plugin called "Advanced TinyMCE Settings" it allows me to change the default TinyMCE configuration. My config under TinyMCE settings is like this:
extended_valid_elements: script[type|src],a[*]
I spent hours and hours on it just won't work. I can't get rid of this "p" tags. They keep continue to publish automatically.
Here are screenshots from Ultimate TinyMCE:
Upvotes: 2
Views: 8353
Reputation: 81
Use this code to remove <p></p>
before editor initialize.
function tinymce_remove_root_block_tag( $init ) {
$init['forced_root_block'] = false;
return $init;
}
add_filter( 'tiny_mce_before_init', 'tinymce_remove_root_block_tag' );
Upvotes: 1
Reputation: 328
Removing unwanted p and br tags (empty ) can be done by adding simple filter function to theme functions.php Here is the code you need to add.
function remove_additional_p($content){
$content = forec_balance_tags($content);
return preg_replace('#<p>\s*+(<br\s*/*>)?|s*</p>#i','',$content);
}
add_filter('the_content','remove_additional_p',20,1);
Upvotes: 2
Reputation: 3622
It can be done without code.
Go to Settings
> TINYMCE Advanced
and check
Stop removing the <p>
and <br />
tags when saving and show them in the HTML editor
Whereas it is bad practice to put scripts in your text area, well you can remove <p>
tags by doing this:
$text=str_ireplace('<p>','',$post->post_conent);
$text=str_ireplace('</p>','',$post->post_conent);
Upvotes: -1