How to Change WordPress’ Default Search Slug (Easy Method 2023) – Digital Boom

Published by Amirshop on

How to Change WordPress' Default Search Slug (Easy Method 2023) – Digital Boom


There are several reasons you might want to change the default WordPress default slug URL. The most important reason could be the exclusion of Google Adsense ad requests to avoid policy violations.

Google Adsense doesn’t allow users to exclude pages that contain query parameters like the WordPress search slug ?s=.

So how to change the default search slug url in WordPress?

You can easily change the default search slug from ?s= to /search/ by adding the following code snippet to your htaccess file:

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

Update the robots.txt file to prevent the new slug from being crawled by using Yoast -> Tools – Edit Files or adding the following to your robots.txt file using your file manager.

Disallow: /search/

And now you can also ask Google Adsense to exclude search pages from showing ads:

Go to your Adsense account -> Ads -> Click on the edit icon next to your domain name -> this will open the Auto ads page. Now select “Exclude pages” in the right sidebar -> add the desired pages -> done.

Exclusions from Google Adsense

This will prevent Google Adsense from serving empty search pages with ads, protecting your site from violating Google Adsense policies.



Source link

Categories: Adsense

0 Comments

Leave a Reply

Avatar placeholder

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