Archived topic
Google webstories on archives
3 replies · Started by Hilton on November 19, 2020
I installed the Google Web Stories plugin (https://wordpress.org/plugins/web-stories/) and when creating a story, I noticed that it kept appearing in the site's search listings, as shown here https://bit.ly/36S9tlk. Is there a way to prevent these web stories from appearing on the website archives?
Hi there,
not sure about this, but you can try this PGP snippet:
add_action( 'pre_get_posts', 'my_search_exclude_filter' );
function my_search_exclude_filter( $query ) {
if ( ! $query->is_admin && $query->is_search && $query->is_main_query() ) {
$searchable_post_types = get_post_types( array( 'exclude_from_search' => false ) );
$post_type_to_remove = 'web-story';
if( is_array( $searchable_post_types ) && in_array( $post_type_to_remove, $searchable_post_types ) ) {
unset( $searchable_post_types[ $post_type_to_remove ] );
$query->set( 'post_type', $searchable_post_types );
}
}
}
I am making the assumption that the web stories post type slug is: web-story
Hi David,
You always have the perfect solution!
Thanks!!
Awesome - glad to hear that works!