Last active
October 15, 2019 11:55
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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