Remove Sitelinks Search Box Schema from Yoast Structured Data
On the 21st of November 2024, Google retired Sitelinks Search Box from SERPs.
Although SearchAction is part of the schema.org standard, it was essentially a Google-specific enhancement. Now they have removed the feature, I don’t see this particular schema piece as being useful to other search engines or consumers of structured data.
Yoast want to keep hold of it for now, so here’s how I removed it.
The SearchAction is part of the website pieces, so we can hook into that with the wpseo_schema_website filter. The potentialAction item key is an array of items, so we loop through them looking for the SearchAction. If it exists, we unset that key and break out of the loop. So if other potentialActions are added in the future, we don’t remove them accidentally.
<?php
/**
* Remove the SearchAction schema from the graph.
*/
add_filter( 'wpseo_schema_website', function( $website ) {
if ( isset( $website['potentialAction'] ) && is_array( $website['potentialAction'] ) ) {
foreach ( $website['potentialAction'] as $key => $action ) {
if ( isset( $action['@type'] ) && $action['@type'] === 'SearchAction' ) {
unset( $website['potentialAction'][$key] );
break;
}
}
}
return $website;
});
The code can be added to your theme’s functions.php file or in a custom plugin.