Latest Tech and Tips

How to Change the Default Search URL Slug in WordPress

16

Do you desire to change the default search URL slug in WordPress? By default, WordPress search URLs are not easy to use. In this write-up, we will certainly reveal you how to conveniently change the default search url slug in WordPress and also make it extra SEO and also easy to use.

Changing default WordPress search URL slug

Why Change Default Search URL Slug in WordPress

WordPress makes use of SEO pleasant URL framework for all web pages on your web site. Typical SEO pleasant WordPress URLs appear 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 rather very easy to recognize for customers along with internet search engine.

However, WordPress still makes use of non-friendly URL for search engine result web page. A regular search URL in WordPress resembles this:

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

This URL framework does not match the remainder of your web site URLs. While some WordPress search plugins enhance the search engine result, the majority of do not do anything concerning the search URL itself.

What if you can make your search URL appear like:

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

Let’s have a look at how to make the WordPress search web page URL slug extra SEO pleasant.

Video Tutorial

Subscribe to WPBeginner

If you do not such as the video clip or require even more guidelines, after that proceed analysis.

Changing Search Page URL Slug in WordPress

For this tutorial you will certainly require to modify your WordPress style documents. If you have not done this previously, after that please have a look at our overview on how to duplicate and also paste codein WordPress

Method 1. Change WordPress Search URL Slug by means of Functions File

This approach is simpler and also suggested for the majority of customers.

First, you require to duplicate and also paste the adhering to code in your style’s functions.php data or a site-specific plugin:

feature wpb_change_search_url() {
if (is_search() && & &! vacant( $_ GET['s'])) {
wp_redirect( home_url( "/search/" ). urlencode( get_query_var('s')) );.
leave();.
}
}
add_action( 'template_redirect', 'wpb_change_search_url' );.

Don’ t neglect to conserve your modifications.

You can currently go to your web site and also attempt making use of the search function. You will certainly discover that the search URL resembles this:

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

Method 2. Change Search URL Slug by means of htaccessFile

The htaccess data is frequently made use of to established redirects and also various other web site setup jobs. You can additionally utilize it to change the default search URL slugin WordPress

Your. htaccess data lies in your web site’s origin folder, and also you will certainly require to make use of FTP or File Manager application in cPanel to modify it. Refer to this overview, if you can not discoverthe htaccess data.

In your.htaccess data, you require to paste the adhering to code at the base:

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

Don’ t neglect to conserve your modifications and also uploadthe htaccess data back to the web server.

You can currently go to your web site and also usage the search function. You will certainly discover the search URL will certainly currently appear like this:

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

We wish this write-up assisted you change the default search URL slugin WordPress You might additionally desire to see our listing of 55+ most desired WordPress pointers, methods, and also hacks.

If you liked this write-up, after that please subscribe to our YouTube Channel for WordPress video clip tutorials. You can additionally discover us on Twitter and also Facebook.