Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Change the Default Search URL Slug in WordPress

When someone searches your site, they might see something like http://example.com/?s=search-term.

Not exactly the cleanest or most professional look, right? It can feel a bit clunky, and unfortunately, it’s not great for user experience or SEO.

After working with WordPress for over a decade, we’ve seen how small changes, like cleaning up search URLs, can make a big impact.

A simpler, more readable URL not only makes your site look more polished but also helps visitors feel more confident navigating it. Plus, search engines love clean URLs too.

In this guide, we’ll walk you through two easy ways to change the default search URL slug in WordPress. We’ll show you how to do it using WPCode (great for beginners) and the .htaccess method (ideal if you’re comfortable with a bit of code).

Both work well, and we’ll guide you every step of the way. 🙌

Changing default WordPress search URL slug

Why Change the Default Search URL Slug in WordPress?

The answer is simple: because the default search URL is messy and not very user-friendly.

By default, WordPress uses an SEO-friendly URL structure for all the pages on your website. Typically, SEO-friendly WordPress URLs look like this:

http://example.com/some-post/
http://example.com/2018/03/news-article/
http://example.com/category/some-category/

As you can see, these URLs are quite easy for visitors to understand. They can simply look at their browser’s address bar and see where they are in your site’s layout.

These URLs also tell search engines useful information about the page so they can rank it correctly and show it to people who are looking for content just like yours.

However, when a WordPress user performs a search on your website, the URL usually looks something like this:

http://example.com/?s=search-term

The extra ?s= characters make this URL more difficult to read and understand, which can confuse both the search engines and your visitors. By changing this URL, you can improve your WordPress search and boost your SEO.

With that being said, let’s see how you can change the search URL. Simply use the links below to jump straight to the method you want to use:

Method 1: Change WordPress Search URL Slug Using WPCode (Recommended)

The easiest way to change the default WordPress search slug is by using WPCode, the best code snippet plugin on the market.

With WPCode, you get a beginner-friendly way to add code snippets in WordPress without editing your theme’s functions.php file. This way, you don’t have to worry about breaking your site.

Some of our partner brands actually use WPCode to add and manage their custom code snippets. It’s been working really well for them, and you can see our detailed WPCode review for more information about it.

WPCode's homepage

The first thing you need to do is install and activate the WPCode plugin on your website. For more details, see our step-by-step guide on how to install a WordPress plugin.

💡 Note: You can use the free WPCode plugin for this tutorial. However, if you need extra features like access to the full code library, code scheduling, and revision history, you may want to upgrade to WPCode Pro.

Upon activation, go to Code Snippets » Add Snippet.

Add Snippet button in WPCode

This will bring you to the ‘Add Snippet’ page, where you can see WPCode’s library of ready-made snippets.

To add your own snippet, just hover your mouse over ‘Add Your Custom Code (New Snippet).’ Then, click on ‘+ Add Custom Snippet’ when it appears.

Select the 'Add Your Custom Code (New Snippet) option from the library

Next, you need to choose the code type from the options that appear.

For this tutorial, click on ‘PHP Snippet.’

Select PHP Snippet as the code type

Now, on the ‘Create Custom Snippet’ page, you can start by entering a title for the custom code snippet.

This can be anything that helps you identify the snippet in the WordPress admin area.

Adding a title to the WordPress code snippet

You can then go ahead and paste the following into the ‘Code Preview’ box:

function wpb_change_search_url() {
	if ( is_search() && ! empty( $_GET['s'] ) ) {
		wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
		exit();
	}
}
add_action( 'template_redirect', 'wpb_change_search_url' );

This code snippet replaces the ‘/?s=search-term’ characters with ‘search,’ so your slug will look something like: http://example.com/search/wordpress

To use something other than ‘search’ in your URL, simply customize the code snippet above.

When you are happy with the code, it’s time to change where the snippet runs by scrolling to the ‘Insertion’ box.

To start, make sure ‘Auto Insert’ is selected. Then, open the ‘Location’ dropdown and choose ‘Frontend Only’ since we will only use this code on our site’s public-facing front end.

WPCode's auto insert code feature

When the snippet is set up how you want it, you can make it live by clicking the ‘Active’ toggle.

Finally, don’t forget to click on ‘Save Snippet.’

Saving a custom PHP snippet using WPCode

Now, visit your site and perform a search.

If you take a look at your browser’s address bar, you’ll see the new SEO-friendly search URL.

A custom WordPress search slug URL

Method 2: Change WordPress Search URL Slug via .htaccess File

Another option is to edit your site’s .htaccess file. This method is more complicated, so it isn’t recommended for beginners. However, it does allow you to change the search URL slug without using a code snippet plugin.

⚠️ Important: Before making any changes, make sure to create a website backup. This is because a tiny mistake in the .htaccess file can break your site.

We recommend using a backup plugin like Duplicator or UpdraftPlus to safely create a full backup. If something goes wrong, you can use an FTP client to revert the changes and restore access.

To access the .htaccess file, you’ll need an FTP client such as FileZilla, or you can use the file manager of your WordPress hosting cPanel.

If this is your first time using FTP, then you can see our complete guide on how to connect to your site using FTP.

For the sake of example, we will use Bluehost‘s file manager app. If you are a Bluehost user, go ahead and log in to your hosting dashboard. Then, navigate to the ‘Websites’ tab and click ‘Settings’ for the site you want to edit.

Bluehost site settings

After that, go to the Quick Links section.

There, click ‘File Manager.’ Around the same area, you will also see your document root path (usually public_html), where you can find the .htaccess file.

Opening Bluehost's file manager

You should now be inside Bluehost’s file manager.

Once you’ve found the .htaccess file in the public_html folder, right-click on it and select ‘Edit.’

Editing the .htaccess file in Bluehost

Now, paste the following code at the bottom of the file:

# Change WordPress search URL
RewriteCond %{QUERY_STRING} \\?s=([^&]+) [NC]
RewriteRule ^$ /search/%1/? [NC,R,L]

This will change the WordPress search slug to the following:

http://example.com/search/your-search-query/

You can change this slug by customizing the code snippet.

Once you’ve done that, don’t forget to click ‘Save Changes.’

Adding custom code to .htaccess

Now, if you perform a search on your site, you’ll notice that it’s using the new slug.

Bonus Tip: Use SearchWP to Create a Custom WordPress Search Engine

The built-in WordPress search block works fine as your website’s search engine. But if you want to offer a better search experience, then you will need SearchWP. It’s the best WordPress plugin to improve your site search.

SearchWP

This WordPress search plugin lets you create custom search algorithms and forms that best suit your users’ and website needs.

For example, you can add a search by category feature so your readers can just focus on looking through content in a specific category. You can even make PDFs and other documents searchable in WordPress.

To learn more about this search plugin, you can read our full SearchWP review.

FAQs: How to Change the Default Search URL Slug in WordPress

We’ve put together answers to some common questions to help you feel more confident about changing the default search URL slug.

Can I change the search URL slug without using any plugins?

Yes, you can edit the .htaccess file directly to change the search URL slug. But keep in mind, this method is more technical and not beginner-friendly. Using a plugin like WPCode is a much safer and easier option.

Will changing the search URL slug affect my site’s SEO?

It can actually help! Clean, user-friendly URLs are preferred by both visitors and search engines. Just make sure to handle things like redirects properly to avoid any SEO issues.

What happens if I make a mistake in the .htaccess file?

A small mistake can break your site and make it inaccessible. That’s why it’s important to back up your site first. If something goes wrong, you can use an FTP client to undo the changes and get things back to normal.

Can SearchWP be used together with a custom URL slug?

Absolutely! SearchWP doesn’t rely on your URL structure, so it will continue to work just fine even if you change the search URL slug. It’s a great way to improve your site’s search while keeping things clean and user-friendly.

We hope this article helped you change the default search URL slug in WordPress. Next up, you can also go through our articles on:

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

18 CommentsLeave a Reply

  1. I liked the WPCode method as it’s easy and no file editing required. I’ve used this on client sites for SEO and user experience. Made the change to show “results”

  2. Hi, I just came across this today and it’s been super helpful. Is there anyway to remove the “You Search For” prefix in the page title when doing a search?

    • That would be added by your specific theme first. We would recommend checking with the support for your theme to see if they have a built-in or recommended way for changing that without needing to modify your theme’s files.

      Admin

  3. Thank you Respected Sir/Madam,

    I am looking for such code because I want to use theme default theme’s search box using “Google Custom Search Engine” for extra revenue. Finally I have done using this code (all credit goes to you Sir / Madam). I have basis knowledge about html ( I don’t learn @ any institution, I learned online….. Let’s go),
    Very Very Thanks again…..

    • You would use the first method and replace the word search with the word you wanted

      Admin

  4. Works great. Any idea why this might leave off closing / as in url.com/search/search-term instead of /search-term/

    • For the first method, depending on your permalinks it may not automatically add a trailing slash, if you wanted one you would need to add the trailing slash to the wp_redirect function or modify your permalink settings.

      Admin

  5. Method 1 doesn’t work if I change “/search/” for another term. I triead “/busca/” that means search in portuguese…

    • Carlos is right. Same goes for method 2 (htacess method. The only word it will work for is “search”. If you try any other word like “result”, “busca”, “whatever”, etc, then you get a 404.

      Very confusing as to why it only works for the word “search”.

      • You may want to ensure you cleared your caching if you’ve edited the code from the article for a word other than search for one possible reason.

        Admin

    • These methods alone won’t work, they only make the «pretty» slug, but the keyword you need to change is the WP rewrite rule for the query.

      You can use this code in your theme’s functions.hp to use any word you want (also includes the rule for the ‘page’ slug):

      function re_rewrite_rules() {
      global $wp_rewrite;
      $wp_rewrite->search_base = ‘buscar’;
      $wp_rewrite->pagination_base = ‘pagina’;
      $wp_rewrite->flush_rules();
      }
      add_action(‘init’, ‘re_rewrite_rules’);

  6. Do you meant that the search result page can be indexed by search engine?
    However, the content in the search result page is a kind of duplicate content as what we can find in the archieve, category or tag pages.

    PS. I am not an expert in SEO and might have wrong concept.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.