Importance of esc_url, esc_attr & esc_html in WP

Quick Summary
- Use esc_html() for text between HTML tags, esc_attr() for attribute values and esc_url() for URLs in href and src.
- Escaping makes a value safe right before printing, and esc_url() also removes links that use unsafe protocols such as javascript.
- Without escaping, a stored or submitted value can inject HTML or JavaScript, so pair it with validating and sanitizing input.
esc_url(), esc_attr() and esc_html() are WordPress escaping functions: they make a value safe right before you print it. Use esc_html() for text between HTML tags, esc_attr() for values inside HTML attributes such as title or value, and esc_url() for URLs in href and src, where it also removes links with unsafe protocols such as javascript:.
Escaping is one of three related practices: validating checks that input is what you expect, sanitizing cleans input before you save it (see sanitization methods for PHP form input), and escaping secures output. Long story short, these functions matter because escaping output, together with sanitizing input, is a critical aspect of web application security: without it, a stored or submitted value can inject HTML or JavaScript into your pages. Escaping protects the output of your own code, while WordPress hardening basics such as blocking PHP in the uploads folder protect the server around it.
Further reading on escaping
1. The Importance of Escaping All The Things
2. Usage of esc_url, esc_attr, and esc_html functions

