[Resolved] Backslash removed from regex when GP Premium activated

Home Forums Support [Resolved] Backslash removed from regex when GP Premium activated

Home Forums Support Backslash removed from regex when GP Premium activated

  • This topic has 5 replies, 2 voices, and was last updated 6 years ago by Tom.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #543426
    Tanya

    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

    #543501
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Are you putting javascript directly into the content editor?

    #543678
    Tanya

    Hi Tom. Yes. Other JavaScript code works fine. Just an issue with the slashes. Would you recommend another approach of inserting tha JavaScript?

    Thanks

    #543946
    Tom
    Lead Developer
    Lead Developer

    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/

    #544175
    Tanya

    Hi Tom.
    Thanks for the tip. I am using Scripts and Styles plugin now. Works great! ๐Ÿ™‚

    #544212
    Tom
    Lead Developer
    Lead Developer

    Awesome ๐Ÿ™‚

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.