Example 1 — Search heading
Show the search words in a heading.
<?php if ( is_search() ) {
echo '<h1>Results for: ' . esc_html( get_search_query() ) . '</h1>';
} ?> How It Works
is_search()is true on search results.get_search_query()returns the search text.esc_html()protects the page from bad input.

