Skip Navigation

[Resolved] Script tag stripped in Editor

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user would like to embed a 3rd party snippet that contains a tag. The editor is stripping the tag.

Solution:
Save the embedded code on a custom field, then create a custom shortcode to return the script:

Relevant Documentation:
https://developer.wordpress.org/reference/functions/add_shortcode/

https://developer.wordpress.org/reference/functions/get_post_meta/

This support ticket is created 5 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 2 replies, has 2 voices.

Last updated by philippeG 5 years ago.

Assisted by: Jamal.

Author
Posts
#1652473
Capture d’écran, le 2020-06-06 à 00.12.02.png
Capture d’écran, le 2020-06-06 à 00.12.14.png

Tell us what you are trying to do?

I try to add a button, provided by another site ("ouvoir.ca"), in a page of the site. This button is actually included in a script tag, which is stripped when I switch from Text tab to Visual tab. I would like to know how could integrate this external code in my page. Note : the button is unique for a page, so I can't use Header and Footer integration for JS code.

Is there any documentation that you are following?

Informations grabbed on forums (Stack Overflow, etc)

Is there a similar example that we can see?

Sure : "<script src="hidden link"></script> <script type="text/javascript" src="hidden link"></script> <div id="ovc-film-button"></div> <script type="text/javascript"> $('#ovc-film-button').ovc( {embed_display:'film_button', film_url: '/2017/les-faux-tatouages', title:'Faux Tatouages, Les', width: 200}); </script>"

What is the link to your site?

hidden link

#1652877

Hello and thank you for contacting the Toolset support.

I believe that the Wysiwyg editor will always strip out tags such as <script> tag.
To work around it, you can make the field a single line or multiline, which do not use a Wysiwyg editor.
Or you can save only the dynamic part of the "ouvoir.ca snippet" and create a custom shortcode to generate the needed markup. In that case, you will need to use the following WordPress functions:
- https://developer.wordpress.org/reference/functions/add_shortcode/
- https://developer.wordpress.org/reference/functions/get_post_meta/

I hope this helps. Let us know your feedback.

#1653333

Thanks for you support. I finally added shortcodes, and it works properly. My issue is resolved now. Thank you!