Change the JSON+LD search URL

Last update: 10 August, 2018

Yoast SEO outputs code to make search in sitelinks work better for your site, read more about that feature here.

If your WordPress install doesn’t use the default example.com/?s={keyword} type search URLs but for instance uses example.com/search/{keyword}, you’ll want to change the output of the JSON+LD code that Yoast SEO puts out. That’s as simple as doing this:

/* Change the search slug to /search/
 * for the JSON+LD output in Yoast SEO
 */
function yst_change_json_ld_search_url() {
return trailingslashit( home_url() ) . 'search/{search_term}';
}
add_filter( 'wpseo_json_ld_search_url', 'yst_change_json_ld_search_url' );

Was this article helpful? ·