Do you want to change the default search URL bar in WordPress? By default, WordPress search URLs are not user friendly. In this article, we will show you how to easily change the default search URL bullet in WordPress and make it more user friendly and SEO friendly.
WordPress uses an SEO friendly URL structure for all the pages on your website. Typical SEO friendly WordPress URLs look like this:
http://example.com/some-page/
http://example.com/2018/03/some-article/
http://example.com/category/some-category/
As you can see, these URLs are quite easy for both users and search engines to understand.
However, WordPress still uses an unfriendly URL for the search results page. A typical WordPress search URL looks like this:
http://example.com/?s=search-term
This URL structure does not match the rest of the URLs on your website. While some WordPress search plugins improve search results, most do nothing about the search URL itself.
What if you can make your search URL look like:
http://example.com/search/your-search-term/
Let's take a look at how to make WordPress search page URL slug more SEO friendly.
If you don't like the video or need more instructions, continue reading.
For this tutorial, you will need to edit your WordPress theme files. If you haven't done this before, then check out our guide on how to copy and paste code into WordPress.
This method is easier and recommended for most users.
First, you need to copy and paste the following code into your theme's functions.php file or a site-specific plugin:
función wpb_change_search_url () if (is_search () &&! empty ($ _GET ['s'])) wp_redirect (home_url ("/ search /"). urlencode (get_query_var ('s'))); salida(); add_action ('template_redirect', 'wpb_change_search_url');
Don't forget to save your changes.
Now you can go to your website and try to use the search function. You'll notice that the search URL looks like this:
http://example.com/search/your-search-query/
The .htaccess file is often used to configure redirects and other website configuration tasks. You can also use it to change the default search URL bar in WordPress.
Your .htaccess file is located in the root folder of your website, and you will need to use the FTP or File Manager application in cPanel to edit it. Please refer to this guide, if you cannot find the .htaccess file.
In your .htaccess file, you need to paste the following code at the bottom:
# Cambiar la URL de búsqueda de WordPress RewriteCond% QUERY_STRING \\? S = ([^ &] +) [NC] RewriteRule ^ $ / search /% 1 /? [NC, R, L]
Don't forget to save your changes and upload the .htaccess file back to the server.
You can now go to your website and use the search function. You'll notice that the search URL will now look like this:
http://example.com/search/your-search-query/
We hope this article helped you change the default search URL bar in WordPress. You may also want to see our list of 55+ Most Wanted WordPress Tips, Tricks, and Tricks.
If you enjoyed this article, please subscribe to our WordPress YouTube Channel video tutorials. You can also find us on Twitter and Facebook.