Does & or & or & mean the same thing in code?

We have a client that uses a wordpress blog, when he pastes in our video embed code it changes &’s into & so for a workaround he has to re-write & as &

Does this break code? Would doing something like <code></code> in wordpress fix the issue?

Read More

Example:

<param name="adServerURL" value="http://plg.website.com/dynamic_preroll_playlist.vast2xml?domain=111aaabbb&amp;pubchannel=KidS&amp;" />

Related posts

Leave a Reply

4 comments

  1. I’m not sure of what you mean, as your text refers to changing & into &. Probably you meant changing the ampersand letter & to &amp;, but here you need to use the “{ }” button to “escape” it to make it visible.

    It’s a correct change. In HTML, the ampersand has a special meaning, and this applies to occurrences in URLs, too. Mostly you can get away with it if you don’t “escape” it, but escaping is the right thing to do—failing to do so may sometimes break the code.

    Using <code> markup has no impact on this.

  2. I did something like this using java script:

    <!-- html -->
    <button onclick='redirect()'>Cart</button>
    <!-- html -->
    <script>
    function redirect()
    {
    var qty = document.getElementById("qty_id").value;
    var url = 'https://domainurl.com/checkout-2/?add-to-cart=362&quantity='+qty;
    var redirecturl = url.replace('amp;','');
    window.location.href = redirecturl; 
    }
    </script>
    
  3. In WordPress specifically, if you’re getting an unwanted &#038 instead of an ampersand, this is most likely coming from esc_url:

    // Replace ampersands and single quotes only when displaying.
    if ( $_context === 'display' ) {
        $url = wp_kses_normalize_entities( $url );
        $url = str_replace( '&amp;', '&', $url ); <!-- See this line!
        $url = str_replace( "'", ''', $url );
    }
    

    Use esc_url_raw instead, which under the hood will simply call esc_url and skip that conditional by passing a different context as argument.