Custom url search result WordPress


With WordPress it is easy to activate readable URLs. Only the search page is not affected by the setting yet, it comes with the syntax ?s as default. But there is a solution to change the URL as you wish.

The following example shows that even if you have permalinks activated, that the URL for the two searchterms wordpress and consulting looks like this: <span class="pln">bueltge</span><span class="pun">.</span><span class="pln">de</span><span class="pun">/?</span><span class="pln">s</span><span class="pun">=</span><span class="pln">wordpress</span><span class="pun">+</span><span class="pln">consulting</span><span class="pun">&amp;</span><span class="pln">submit</span><span class="pun">=</span><span class="typ">Search</span>. With a little function, which communicates with the redirect, you can adjust the URL. In my case the URL with the two searchterms look like this with the following function: <span class="pln">bueltge</span><span class="pun">.</span><span class="pln">de</span><span class="pun">/</span><span class="pln">search</span><span class="pun">/</span><span class="pln">wordpress</span><span class="pun">+</span><span class="pln">consulting</span>.

Within WP-function <span class="pln">wp_redirect</span> I set the output, that the term search will be added to the home-url of your installation and added by the searchterms. There are many possibilities to adjust the URL.

Yes, it is also possible via htacces rules, but the source is an example for custom solutions on an redirect.

I would recommend to put the function in a Plugin or in the <span class="pln">functions</span><span class="pun">.</span><span class="pln">php</span> of your theme. Any other or better ideas to accomplish this? Please let us know in the comment area.



Change the Search-URL of WordPress