Change the JSON+LD search URL

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.

We highly recommend taking a backup of your site before you edit theme files.

To change the URL that Yoast outputs as part of the JSON+LD Code:

/* 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' );

Disable JSON+LD

You can disable the JSON+LD output completely by adding the code below to the functions.php file of your theme.

add_filter('wpseo_json_ld_output', '__return_false');

Was this article helpful? ·