最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

escaping - esc_attr not working in shortcode

programmeradmin2浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论