user1437328
user1437328

Reputation: 15846

How to put in script tags inside Wordpress Editor?

Been struggling with this problem for hours!

Websites like CSSDeck gives an embed code that consists of a pre and script tag. You can embed that code inside your blog and that stuff will show up. Here is an example of what I mean.

But when I use that code in my Wordpress blog, it strips out the script tag. How can I solve this problem ? Also can I solve it in a way so that I can add script tags from a whitelist domains that I defined somewhere ?

Some Help would be really appreciated.

Cheers

Upvotes: 2

Views: 9484

Answers (4)

Dhara Talaviya
Dhara Talaviya

Reputation: 631

Add TinyMCE array :

$editor_settings['tinymce '] = array(
        'extended_valid_elements' => 'script[src|async|defer|type|charset]',
         
      );

For wp_kses allow to add script:

function allow_script_tags( $allowedposttags ){
  $allowedposttags['script'] = array(
      'src' => true,
      'height' => true,
      'width' => true,
      'charset' => true,
      'async' =>true
    );
  return $allowedposttags;
}

add_filter('wp_kses_allowed_html','allow_script_tags', 50);

Upvotes: 0

Thariama
Thariama

Reputation: 50832

You can use the tinymce settings valid_elements and valid_children to define what tinymce will strip out and what tinymce will keep.

Upvotes: 1

s_ha_dum
s_ha_dum

Reputation: 2850

You can paste (at least simple) scripts into the HTML version of the editor, but not into the Visual version. The Visual version will encode the script, thus breaking it. I tested this a day or two ago on an almost up-to-date WordPress. If your script has dependencies like JQuery, it may not work though. It depends on when the dependencies load and how the script is written.

Upvotes: 0

Anshu
Anshu

Reputation: 7853

If you wish to add javascript to your page you can try the Function Reference/wp enqueue script

Also, you should have a look at less filter plugin and Advanced Excerpt plugin

Upvotes: 0

Related Questions