[Support request] Google webstories on archives

Home Forums Support [Support request] Google webstories on archives

Home Forums Support Google webstories on archives

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1537388
    Hilton

    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?

    #1537468
    David
    Staff
    Customer Support

    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

    #1538315
    Hilton

    Hi David,

    You always have the perfect solution!

    Thanks!!

    #1538567
    David
    Staff
    Customer Support

    Awesome – glad to hear that works!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.