79591332

Date: 2025-04-24 19:31:18
Score: 0.5
Natty:
Report link

If the goal is to simply redirect to the 404 php when searching. This solution works with less code.

Also, this solution will make sure the search query URL params "domain.com/?=furniture" is removed from address bar when the page reloads (vs. the other approaches which still show the search query URL params).

/** Remove the search capability by redirecting all search queries to the 404 page, in the "functions.php" file **/

function redirect_search_to_404_page( ) {
    if ( is_search() && !is_admin() ) {
        wp_redirect( '/404' );
        exit;
    }
}
add_action( 'wp_footer', 'redirect_search_to_404_page' );
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Cleo