Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active August 2, 2021 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jchristopher/512654fb6d7a3a666468 to your computer and use it in GitHub Desktop.
Save jchristopher/512654fb6d7a3a666468 to your computer and use it in GitHub Desktop.
Use a Shortcode to prevent SearchWP from indexing partial content, see https://searchwp.com/docs/kb/prevent-indexing-segments-content/
<?php
// tell SearchWP to process shortcodes
add_filter( 'searchwp_do_shortcode', '__return_true' );
// if the SearchWP indexer is running prevent returning the
// content between [searchwp_no_index] and [/searchwp_no_index]
function shortcode_searchwp_no_index( $atts, $content = null ) {
// if the searchwp_indexer_running action fired, the indexer is running so don't return anything
return did_action( 'searchwp_indexer_running' ) ? '' : $content;
}
add_shortcode( 'searchwp_no_index', 'shortcode_searchwp_no_index' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment