Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Created March 9, 2022 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save searchwpgists/e65a3c401b1ea5b173780e0f8dcfe69e to your computer and use it in GitHub Desktop.
Save searchwpgists/e65a3c401b1ea5b173780e0f8dcfe69e to your computer and use it in GitHub Desktop.
Add a Shortcode to exclude content from SearchWP's index
<?php
// Add a Shortcode to exclude content from SearchWP's index.
// @link https://searchwp.com/documentation/knowledge-base/prevent-indexing-segments-of-content/
add_shortcode( 'searchwp_no_index', function( $atts, $content = null ) {
// If the indexer is running do not return anything,
// else return the content contained in the Shortcode.
return did_action( 'searchwp\indexer\batch' ) ? '' : $content;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment