Advertisements

get_search_link

Definition:
function get_search_link( $query = '' ) {}

Retrieve permalink for search.

Parameters

  • string $query: Optional. The query string to use. If empty the current query is used.

Defined filters

  • search_link
    apply_filters( 'search_link', $link, $search )

Source code

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 unencoded.

		$link = str_replace( '%search%', $search, $permastruct );

		$link = home_url( user_trailingslashit( $link, 'search' ) );

	}



	return apply_filters( 'search_link', $link, $search );

}

1675

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: