Challenge - 5 Problems
WordPress Escaping Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this WordPress escaping function?
Consider the following PHP code snippet in a WordPress theme template:
What will be the output rendered in the browser?
<?php
$user_input = '<script>alert("XSS")</script>';
echo esc_html( $user_input );
?>
What will be the output rendered in the browser?
Wordpress
<?php
$user_input = '<script>alert("XSS")</script>';
echo esc_html( $user_input );
?>Attempts:
2 left
💡 Hint
esc_html() converts special HTML characters to safe entities.
✗ Incorrect
esc_html() escapes HTML special characters like <, >, and quotes so they display as text, preventing scripts from running.
📝 Syntax
intermediate1:30remaining
Which option correctly escapes a URL for safe output in WordPress?
You want to safely output a URL stored in $url variable inside an HTML attribute in WordPress. Which of the following is the correct escaping function to use?
Attempts:
2 left
💡 Hint
Use the function designed specifically for URLs.
✗ Incorrect
esc_url() is designed to sanitize and escape URLs for safe output in HTML attributes or links.
🔧 Debug
advanced2:30remaining
Why does this WordPress code output raw HTML instead of escaped text?
Given this code:
Why does the browser render Hello as bold text instead of showing the tags as text?
<?php
$content = '<strong>Hello</strong>';
echo esc_attr( $content );
?>
Why does the browser render Hello as bold text instead of showing the tags as text?
Wordpress
<?php
$content = '<strong>Hello</strong>';
echo esc_attr( $content );
?>Attempts:
2 left
💡 Hint
esc_attr() is for attribute values, not general HTML content.
✗ Incorrect
esc_attr() escapes quotes and special chars for attributes, but when echoed in body content, HTML tags still render. Use esc_html() to escape tags in body.
❓ state_output
advanced2:30remaining
What is the output of this WordPress code with nested escaping?
Analyze this code:
What will be displayed in the browser?
<?php
$data = '<a href="http://example.com">Link</a>';
echo esc_html( esc_attr( $data ) );
?>
What will be displayed in the browser?
Wordpress
<?php
$data = '<a href="http://example.com">Link</a>';
echo esc_html( esc_attr( $data ) );
?>Attempts:
2 left
💡 Hint
esc_attr() escapes quotes and special chars, esc_html() escapes HTML entities again.
✗ Incorrect
esc_attr() converts quotes to entities, then esc_html() converts < and > to entities, so output shows all escaped characters with & prefixes.
🧠 Conceptual
expert3:00remaining
Which WordPress escaping function should you use to safely output user input inside a JavaScript block?
You want to output user input safely inside a JavaScript block in a WordPress theme. Which escaping function is the best choice?
Attempts:
2 left
💡 Hint
Think about escaping for JavaScript context, not HTML or URLs.
✗ Incorrect
esc_js() escapes data for safe use inside JavaScript code blocks, preventing injection attacks.