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?

1 Answer 1


I 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.