On this page
get_search_link( string $query = '' ): string
Retrieves the permalink for a search.
Parameters
$querystring Optional-
The query string to use. If empty the current query is used.
Default:
''
Return
string The search permalink.
Source
File: wp-includes/link-template.php. View all references
function get_search_link( $query = '' ) {
global $wp_rewrite;
if ( empty( $query ) ) {
$search = get_search_query( false );
} else {
$search = stripslashes( $query );
}
$permastruct = $wp_rewrite->get_search_permastruct();
if ( empty( $permastruct ) ) {
$link = home_url( '?s=' . urlencode( $search ) );
} else {
$search = urlencode( $search );
$search = str_replace( '%2F', '/', $search ); // %2F(/) is not valid within a URL, send it un-encoded.
$link = str_replace( '%search%', $search, $permastruct );
$link = home_url( user_trailingslashit( $link, 'search' ) );
}
/**
* Filters the search permalink.
*
* @since 3.0.0
*
* @param string $link Search permalink.
* @param string $search The URL-encoded search term.
*/
return apply_filters( 'search_link', $link, $search );
}
Hooks
- apply_filters( 'search_link',
string $link ,string $search ) -
Filters the search permalink.
Related
Uses
| Uses | Description |
|---|---|
| get_search_query() wp-includes/general-template.php | Retrieves the contents of the search WordPress query variable. |
| user_trailingslashit() wp-includes/link-template.php | Retrieves a trailing-slashed string if the site is set for adding trailing slashes. |
| WP_Rewrite::get_search_permastruct() wp-includes/class-wp-rewrite.php | Retrieves the search permalink structure. |
| home_url() wp-includes/link-template.php | Retrieves the URL for the current site where the front end is accessible. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| get_search_feed_link() wp-includes/link-template.php | Retrieves the permalink for the search results feed. |
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_search_link