Ok, I’ve seen solutions which go halfway to sorting out this problem, but nothing definitive, and nothing that 100% solves my problem.

Scenario:

  • In HTML mode, I add some javascript to a post I’m editing.
  • I switch to Visual, then back to HTML, and the tag and all of its content are gone.

How do I stop this from happening? I’ve tried adding custom code to my functions.php trying to access the extended_valid_elements for TinyMCE, but nothing works.

Please help!

3 Answers
3

Adding JS to the content is very, very bad practice, and it’s just asking to be hacked.

Add it via a shortcode, or if you really must, use a post meta/custom fields to store the js and display it after the content in your template using echo get_post_meta($post->ID,'post_javascript',true );

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *