4

I want to know use of esc_attr()? how it is used? Any example would be highly help!

esc_attr( $variable )
2

2 Answers 2

8

esc_attr() is written specifically for escaping a string that is to be used as an html attribute, which means also escaping single and double-quote characters etc.

In general, it's better to use the data validation API that WP provides rather than the generic PHP functions.

1
  • 1
    sure, it works now! thanks for the concept clearance!
    – Nimesh
    Commented Mar 28, 2018 at 17:37
1

esc_attr() is writing for escaping a string that is to be used as an html attribute. When escaping the values of attributes that accept URIs (like href and src), it is important to pass the value through esc_url().

Note: that when using esc_url(), you don’t need to also use esc_attr().

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.