Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save BrElio/e2d86a2f5d3c801edd5dd44c174cc15a to your computer and use it in GitHub Desktop.
Save BrElio/e2d86a2f5d3c801edd5dd44c174cc15a 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