WordPress.org

Forums

[resolved] wptexturize convert ampersands in SCRIPT tags (3 posts)

  1. ianhaycox
    Member
    Posted 2 years ago #

    According to the documentation

    http://codex.wordpress.org/Function_Reference/wptexturize

    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.

    http://xx.com/wp-admin/admin-ajax.php?action=foo&bar=1&foobar=2

    gets converted to,

    http://xx.com/wp-admin/admin-ajax.php?action=foo&amp; #038;bar=1& #038;foobar=2

    Is this expected behaviour ?

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

    Thanks.

  2. tobek
    Member
    Posted 2 years ago #

    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 =)

  3. ianhaycox
    Member
    Posted 2 years ago #

    Thanks for the tip.

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.