I have a shortcode that outputs a block of html. One element in the block is an anchor tag with an image caption in the title attribute. Some of the captions I am using have double quotes in them, so I am wrapping them in esc_attr(), but none of the quotes are being encoded. If I put an echo statement in the shortcode with esc_attr() around the caption, it outputs an encoded string, but it doesn't seem to work when I return the html as you are supposed to do in a shortcode. Is this the nature of esc_attr()? If so, how can I encode a string to be returned from a shortcode?
I have a shortcode that outputs a block of html. One element in the block is an anchor tag with an image caption in the title attribute. Some of the captions I am using have double quotes in them, so I am wrapping them in esc_attr(), but none of the quotes are being encoded. If I put an echo statement in the shortcode with esc_attr() around the caption, it outputs an encoded string, but it doesn't seem to work when I return the html as you are supposed to do in a shortcode. Is this the nature of esc_attr()? If so, how can I encode a string to be returned from a shortcode?
Share Improve this question asked Mar 1, 2014 at 4:11 jncoatesjncoates 614 bronze badges1 Answer
Reset to default 1I think I have figured out the problem, though I have yet to solve it. I am running the shortcode in a WP Types custom WYSIWYG field. The shortcode works perfectly everywhere else, including directly in my theme files and in the native WordPress content WYSIWYG, so it seems it is a bug in WP Types. I'm submitting a bug report, but hopefully my findings will help someone in the meantime.