WordPress get_search_link() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Returns a URL

Definition

In WordPress, get_search_link() returns the URL of the search results page for a word or phrase. It is the address you would reach after typing that word in the search box.

If you do not pass a word, it uses the current search. Depending on your permalink setting, the address looks like /?s=hooks or /search/hooks/.

Syntax

Pass a search word and print the result with esc_url().

WordPress
<?php echo esc_url( get_search_link( 'hooks' ) ); ?>
CallWhat it does
get_search_link( 'hooks' )The search URL for the word hooks.
get_search_link()The search URL for the current search.
get_search_link( 'wordpress' )The search URL for wordpress.

It returns the URL. It does not run a search by itself.

Full declaration
WordPress
get_search_link( string $query = '' ): string

Parameters

ParameterDescription
$querystring. The search term. If empty, WordPress uses the current search term.

Return Value

Return ValueDescription
stringThe URL of the search results page.

WordPress Examples

Three short examples. Each one shows the code and what it prints or does.

Example 1 — Get a search URL

Create a link to the results for one word.

WordPress
<?php
echo esc_url( get_search_link( 'hooks' ) );

How It Works

  1. hooks is the search word.
  2. With pretty permalinks the URL looks like /search/hooks/.
  3. With plain permalinks it is /?s=hooks.

Example 3 — Use the current search

On a search page, call it with no argument.

WordPress
<?php
// Visitor opened /?s=wordpress
echo esc_url( get_search_link() );

How It Works

  1. No word is passed.
  2. WordPress reads the current search term.
  3. It returns the link for the same search.

Frequently Asked Questions

It returns the URL of the search results page for a word you give it.
It uses the search term of the current page.
No. It only builds the URL. The search runs when someone opens it.
It depends on your permalink setting. Plain permalinks use ?s=word. Pretty permalinks use /search/word/.
Use get_search_query().

Next: get_search_query()

Return the current search word, escaped by default.

get_search_query() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful