Site icon Anthony Carbon

How to convert your html entities on the map JS code?

On my current, I have this “martygeocoderaddress” custom fields and it contains a string with Queen Anne’s. On my JS code below

Wrong

html += '';
html += '<?php echo get_post_meta( $product->id , 'martygeocoderaddress' , true ); ?>';
// Output is 'Queen Anne's' which is wrong and this can't be read by your JS code. By using this htmlentities( 'string', ENT_QUOTES );, the "'" will convert to &#039;.

Correct

Example

html += '';
html += '<?php echo htmlentities( get_post_meta( $product->id , 'martygeocoderaddress' , true ), ENT_QUOTES ); ?>';
// Output is  'Queen Anne&#039;s' which is correct. No conflict on JS.
Exit mobile version