How To Change Search URL on WordPress

  • 2 comments
  • 2 Comments
    Posted 19 Sep 2011 in WordPress Tricks

    We already know that WordPress Search URL is http://wpgpl.com/search/keyword right? Now we got nicely tips and we will show you how to change this search URL permalink. This tips coming from Andrew Keith. You need to paste this code on functions.php to make it works.

    Open your functions.php on your theme and add this code

    function custom_search_url( $search_rewrite ) {
    if( !is_array( $search_rewrite ) ) { return $search_rewrite; }
    
    $new_array = array();
    foreach( $search_rewrite as $pattern => $s_query_string ) {
    $new_array[ str_replace( 'search/', 'new-search-url/', $pattern ) ] = $s_query_string;
    }
    $search_rewrite = $new_array;
    unset( $new_array );
    return $search_rewrite;
    }
    add_filter("search_rewrite_rules", "custom_search_url");

    Please notes this code didn’t redirect any /?s=Search but this code will redirect any /search/ into something else domain. We hope this tutorial to change search URL on WordPress worked on you


    2 Comments

    1. িhabib

      It does not work.

      Reply
      • WPGPL Team

        Kindly specify what exactly fails to work.

        Reply


    Add Your Comment

    Enter your comment*:

    * Required fields