Monday, November 23, 2020
Home Blogging How to Change the Default Search URL Slug in WordPress

How to Change the Default Search URL Slug in WordPress

Do you wish to change the default search URL slug in WordPress? By default, WordPress search URLs will not be consumer pleasant. On this article, we are going to present you the right way to simply change the default search url slug in WordPress and make it extra search engine marketing and consumer pleasant.

Why Change Default Search URL Slug in WordPress

WordPress makes use of search engine marketing pleasant URL construction for all pages in your web site. Typical search engine marketing pleasant WordPress URLs seem like this:

http://instance.com/some-page/
http://instance.com/2018/03/some-article/
http://instance.com/class/some-category/

As you’ll be able to see, these URLs are fairly straightforward to know for customers in addition to serps.

Nonetheless, WordPress nonetheless makes use of non-friendly URL for search outcomes web page. A typical search URL in WordPress seems like this:

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

This URL construction doesn’t match the remainder of your web site URLs. Whereas some WordPress search plugins enhance the search outcomes, most don’t do something in regards to the search URL itself.

What if you can also make your search URL seem like:

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

Let’s check out the right way to make the WordPress search web page URL slug extra search engine marketing pleasant.

Altering Search Web page URL Slug in WordPress

For this tutorial you will want to edit your WordPress theme recordsdata. Should you haven’t carried out this earlier than, then please check out our information on the right way to copy and paste code in WordPress.

Technique 1. Change WordPress Search URL Slug by way of Capabilities File

This technique is simpler and really useful for many customers.

First, you have to copy and paste the next code in your theme’s features.php file or a site-specific plugin:

1
2
3
4
5
6
7
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' );

Don’t neglect to save lots of your modifications.

Now you can go to your web site and check out utilizing the search characteristic. You’ll discover that the search URL seems like this:

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

Technique 2. Change Search URL Slug by way of htaccess File

The .htaccess file is commonly used to arrange redirects and different web site configuration duties. You can even use it to vary the default search URL slug in WordPress.

Your .htaccess file is situated in your web site’s root folder, and you will want to make use of FTP or File Supervisor app in cPanel to edit it. Check with this information, when you can’t discover the .htaccess file.

In your .htaccess file, you have to paste the next code on the backside:

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

Don’t neglect to save lots of your modifications and add the .htaccess file again to the server.

Now you can go to your web site and use the search characteristic. You’ll discover the search URL will now seem like this:

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

You May Also Like : How to Add YouTube Subscribe Button in WordPress

We hope this text helped you alter the default search URL slug in WordPress. You might also wish to see our listing of 55+ most needed WordPress ideas, tips, and hacks.

If you liked this article, make sure to hit the bell for getting our latest updates and share this article with your friends in every social media platforms.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

50 Best Online Jobs From Home For Students – Earn 20K PM

In latest years, the alternatives for online jobs from home for students have gained great reputation. This is as a result of many of the...

Best Answers to the Question “Why should you be hired for this Internship?”

What is the greatest approach to ace an internship interview? Especially for a more energizing who has by no means appeared for a job-related...

Does Instagram Notify You if Someone Screenshots Your Story?

When Snapchat first burst on the scene, there have been loads of individuals very completely happy concerning the prospect of sending pictures to people...

How to Change Background Color on Instagram Story

It's arduous for me to recollect Instagram earlier than the tales characteristic was launched — it is a simple possibility for sharing updates and...

Recent Comments