By default WordPress use a + between spaces whenever we search for something on a blog which is built on WordPress. Is there any way to change that + into a hyphen.
By default WordPress use a + between spaces
No, it doesn't. WordPress doesn't generate
+ characters, it doesn't use those characters, and it can't see them.
So Where Does the
+ Come From?
The browser and URLs. Spaces in URL parameters are encoded as
+ characters or
%20. Forms specifically become
When data that has been entered into HTML forms is submitted, the form field names and values are encoded and sent to the server in an HTTP request message using method GET or POST, or, historically, via email. The encoding used by default is based on an early version of the general URI percent-encoding rules, with a number of modifications such as newline normalization and replacing spaces with + instead of %20. The media type of data encoded this way is application/x-www-form-urlencoded, and it is currently defined in the HTML and XForms specifications. In addition, the CGI specification contains rules for how web servers decode data of this type and make it available to applications.
Search URLs convert
"test data" to
test+data because that's how URL parameters generated by HTML forms are meant to work.
But Can It Be Done?
Is there any way to change that + into a hyphen.
Not without causing major problems, and unexpected bugs. To do this you would need to intercept the form inputs and replace spaces in the input with a
Then, you would need to intercept it on the PHP side and undo the change. As a result it will be impossible to search for things that contain hyphens. This will also break search functionality in a lot of themes and plugins.
This would also break most search plugins, and interfere with SEO plugins, which will interpret the search query as a single word with hyphens.