Archived topic
Backslash removed from regex when GP Premium activated
5 replies · Started by Tanya on April 6, 2018
Hi,
I have the following Java Script code on one of my pages
words = words .replace(/^\s+|\s+$/g, '')
As soon as I activate GP Premium theme and save the page, backslashes get removed and I am left with
words = words .replace(/^s+|s+$/g, '')
I tried 2 slashes. When I save the page 1-st time, regex works because I am left with 1 slash. When I save page 2-nd time, regex stops working because escape character is not there.
words = words .replace(/^\\s+|\\s+$/g, '')
Could this be a bug in the theme? I am using sections.
Thanks
Hi there,
Are you putting javascript directly into the content editor?
Hi Tom. Yes. Other JavaScript code works fine. Just an issue with the slashes. Would you recommend another approach of inserting tha JavaScript?
Thanks
Javascript shouldn't typically be added within the editor - it will strip parts of it and it will break.
However, this article has some options that might help: https://www.godaddy.com/garage/3-ways-to-insert-javascript-into-wordpress-pages-or-posts/
Hi Tom.
Thanks for the tip. I am using Scripts and Styles plugin now. Works great! :)
Awesome :)