Skip to content

Instantly share code, notes, and snippets.

@swissspidy
Last active September 15, 2021 15:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save swissspidy/737f608f140b6034abd0d38539ac6eb5 to your computer and use it in GitHub Desktop.
Save swissspidy/737f608f140b6034abd0d38539ac6eb5 to your computer and use it in GitHub Desktop.
Mini-plugin to force exclude Web Stories from the built-in WordPress search results
<?php
/**
* Plugin Name: Web Stories Force Exclude From Search
* Description: Web Stories are by default excluded from the built-in WordPress search results. But some plugins might be interfering with that. This plugin tries to force-exclude stories again.
* Plugin URI: https://wp.stories.google/
* Author: Pascal Birchler, Google
* Author URI: https://opensource.google.com/
* Version: 0.0.2
* License: Apache License 2.0
* License URI: https://www.apache.org/licenses/LICENSE-2.0
*/
add_filter(
'register_post_type_args',
static function ( $args, $name ) {
if ( 'web-story' === $name ) {
$args['exclude_from_search'] = true;
}
return $args;
},
10,
PHP_INT_MAX
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment