Support » Plugins » Hacks » wptexturize convert ampersands in SCRIPT tags

  • Resolved ianhaycox


    According to the documentation

    wptexturize is meant to skip processing text within various tags like PRE, SCRIPT etc, however it always seems to convert ampersands to #038;

    For example,

    wptexturize('<XXXscript type="text/javascript"> var x = "Hello & goodbye"; </script>');

    correctly returns:
    NOTE – I’ve added spaces for display reasons.

    <XXXscript type="text/javascript"> var x = & #8220;Hello & #038; goodbye& #8221;; </script>

    With the SCRIPT tag,

    wptexturize('<script type="text/javascript"> var x = "Hello & goodbye"; </script>');

    <script type="text/javascript"> var x = "Hello & #038; goodbye"; </script>

    it correctly ignores the quotes but still convert the ampersand.

    This causes a real problem with AJAX requests as any GET parameters are not passed, e.g.

    gets converted to,; #038;bar=1& #038;foobar=2

    Is this expected behaviour ?

    If it is then is there a workaround, bar removing the wptexturize filter ?


Viewing 2 replies - 1 through 2 (of 2 total)
  • tobek


    This is a pain. But a workaround is to use \u0026 instead of &. You can specify any unicode character in a JS string using \u####, and the result is the same as entering the actual character, but WordPress passes it over unharmed =)



    Thanks for the tip.

    A better workaround than the one I had. Much cleaner.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wptexturize convert ampersands in SCRIPT tags’ is closed to new replies.