2

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&amp;uniq=150&amp;locationId=287500&amp;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&amp;uniq=150&amp;locationId=287500&amp;lang=en_AU">
    </script>
    <script src="http://www.tripadvisor.com.au/WidgetEmbed-excellent?uniq=150&amp;locationId=287500&amp;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:

enter image description here

3 Answers 3

2

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);
Sign up to request clarification or add additional context in comments.

1 Comment

This code works! TY
1

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

Comments

-1

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

enter image description here

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

3 Comments

Thank you for your answer. I installed TINYMCE Advanced and checked "Stop removing the <p> and <br /> tags" option. Nothing changed. "script" tags are still being wrapped by "p" tags.
should I put this in my function.php under my theme?
Sorry didn't work either. I have only activcated TINYMCE Advanced plugin at the moment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.