Example 1 — Show a results heading
A classic use in search.php.
<?php
// Visitor opened /?s=hooks
echo '<h1>Results for: ' . get_search_query() . '</h1>'; How It Works
- WordPress reads
hooksfrom the URL. get_search_query()returns it.- It is already escaped, so you can print it right away.

