How To Change The Default Search URL Slug In WordPress
How To Change The Default Search URL Slug In WordPress | URL Optimization WordPress

Do you want to modify WordPress’s default search URL slug? WordPress does not make your URLs easy to remember or SEO friendly by default, which is a major flaw. Since, the SEO of your website influences how high it will rank on search engines such as Google and Bing, there are numerous strategies to increase your rankings. The issue is that most of the default WordPress settings are not SEO friendly, necessitating their modification. 

So, we’ll show you how to exactly modify the default search url slug in WordPress so that it is more user and SEO friendly. 

In WordPress, what exactly is a slug?

The slug is the changeable part of a page’s URL in WordPress. The slug, which appears at the end of a URL, usually consists of keywords separated by hyphens. It may also include the day, month, time, random digits, the author name, and more, depending on the site’s permalink structure.

The scheme is the first thing you’ll notice, with https:// (or http:// if the site isn’t secure) being the most common. Then there’s the subdomain, which in this case is “blog” and in others is simply “www.” The top-level domain, which is usually.com, is followed by the website’s name, which is the second-level domain.

You can watch the video tutorial below for this article:

After the first slash, the subdirectory appears, showing which part of the website we’re in. Because we’re on the HubSpot blog’s website section, the subfolder for this article is “website.”

The slug comes after the second slash.

Why is it suggested to optimize the default search URL?

When search engines crawl your website, they check for clues about the content’s topic in a variety of locations, including the title, headers, body, picture alt text, meta description, and even the URL.

Search engines check for URLs as one of the first things. They also help to create a positive initial impression for your readers. URLs that are too long or contain strings of random figures and letters appear less trustworthy and clickable than URLs that provide information about the content of the page.

As a result, optimising your URLs is a critical component of enhancing your on-page SEO.

What’s Wrong with the Default Search URL?

The distinction between a good and a bad URL is considerably easier to spot. Take a look at a typical search URL.

www.ExampleWebsite.com/?s=New+Post 

In this case, we were looking for a new post.

Now let’s take a look at the rest of your website’s links:

www.ExampleWebsite.com/a-page

Do you see a distinction?

It’s easy to type a URL that just contains the page or category name, but it’s not so easy to search for “?s=search-term,” so instead, your search URL should look like this:

www.ExampleWebsite.com/search-term

A good rule of thumb for URLs is that they are usually better for everything if they are easy to remember and help shorten the URL length.

How To Change The Default Search URL Slug In WordPress?

To get started, first log into your WordPress account. Navigate to the Dashboard section.

How To Change The Default Search URL Slug In WordPress
  • From the drop-down option, choose Appearance.
  • Then, go to the Theme Editor section.
  • Under the Theme Files, click on (functions.php)
How To Change The Default Search URL Slug In WordPress
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’ );
How To Change The Default Search URL Slug In WordPress

NOTE: Before making any kind of code-related changes, it is suggested to take a backup of your website, just in case anything goes wrong, you can restore it later using the backup.

  • Now click on the Update File to save it.
How To Change The Default Search URL Slug In WordPress

You may now perform a quick search on your website to see whether your URL has changed. Only the search query will be seen after the “?s=” has been deleted. A “+” symbol will be used to separate each word used in the search.

Congratulations for simplifying your search URL and making it more search engine friendly. If you wish to undo this, simply delete the code you put to your functions file, and the URL structure will revert to its original state.

Also Read: How To Change WordPress JPEG Image Compression

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Need Professional Help?

We can help you with website fixes and ongoing maintenance.