Leon Gaban
Leon Gaban

Reputation: 39028

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?

Example:

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

Upvotes: 9

Views: 39707

Answers (4)

Lucas Bustamante
Lucas Bustamante

Reputation: 17198

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;', '&#038;', $url ); <!-- See this line!
    $url = str_replace( "'", '&#039;', $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.

Upvotes: 1

Kaif
Kaif

Reputation: 49

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>

Upvotes: 0

Robert
Robert

Reputation: 3074

Technically yes they are all the same thing. Since it's wordpress I would recommend using the &#038; as that's the encoded version of the ampersand & or &amp;.

WordPress references:

http://wordpress.org/support/topic/how-to-get-rid-of-amp-and-038

http://wordpress.org/support/topic/unwanted-characters-038

Upvotes: 8

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201628

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.

Upvotes: 0

Related Questions