Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active October 15, 2019 11:55
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 jchristopher/fd7ec48a6052e407e6a3dc0e8cfe4789 to your computer and use it in GitHub Desktop.
Save jchristopher/fd7ec48a6052e407e6a3dc0e8cfe4789 to your computer and use it in GitHub Desktop.
Shortcode to disable default output SearchWP "Did you mean?" and add your own
<?php
class MySearchwpElementorDidYouMean {
private $args;
function __construct() {
add_filter( 'searchwp_auto_output_revised_search_query', '__return_false' );
add_action( 'searchwp_revised_search_query', function( $args ) {
$this->args = $args;
});
add_shortcode( 'searchwp_did_you_mean', function() {
if ( empty( $this->args ) ) {
return '';
}
ob_start();
echo '<p class="searchwp-revised-search-notice">';
echo 'No results found for <em class="searchwp-revised-search-original">' . esc_html( implode( ' ', $this->args['original_terms'] ) ) . '</em>. Showing results for <em class="searchwp-suggested-revision-query">' . esc_html( implode( ' ', $this->args['terms'] ) ) . '</em>';
echo '</p>';
$output = ob_get_contents();
ob_end_clean();
return $output;
} );
}
}
new MySearchwpElementorDidYouMean();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment