PHP’s urlencode()
function replaces spaces with +
s, so that’s why that’s happening for you.
WordPress provides the sanitize_title()
function, which is used (among other things) to generate a post slug from the post’s title.
/** * Change search page slug. */
function wp_change_search_url() {
if ( is_search() && ! empty( $_GET['s'] ) ) {
wp_redirect( home_url( "/tag/" ) . sanitize_title( get_query_var( 's' ) ) );
exit();
}
}
add_action( 'template_redirect', 'wp_change_search_url' );
Related Posts:
- Change default search URL slug in wordpress with Custop Post Type as Search target
- Need to return a list based on Slug
- how to limit search to post titles?
- How does WordPress search work behind the scenes?
- Remove some pages from search
- WordPress blog with 30 000 posts: poor search performance
- How do I filter the search results order?
- Link to search page without search parameter
- Search/Replace for editor in HTML-mode
- Do I need to sanitize WordPress search query?
- Neither the_excerpt() nor the_content() works properly?
- WordPress 3.6, searchform.php problems
- Add custom parameters to JSON API search query?
- How to stop _wpnonce and _wp_http_referer from appearing in URL
- Return all Tags from search results
- Search results with custom loop don’t update when paged
- Does WP search natively return results sorted by type (post, post type, page, category…)?
- How do I properly redirect outbound links with special characters
- Conditional tag search-no-results
- Refine Search Results
- pre_get_posts and search query for admin
- Display Categories in Search Results
- intellisense in wp search
- Is it possible to search authors by profile field?
- Search result conditonal tag
- Advanced Search by minimum/maximum values
- How to search in two different wordpress blogs by using a single searchform?
- Get search term not on searh results page?
- Alphabetical search
- Custom Search Query running on every page
- Use search in fancybox
- Two Search Boxes: one all content, one only titles
- Keep query string in url after executing a serch
- How can I remove the search window?
- Search Everything & WP 3.7 update issues [closed]
- custom wp_dropdown_categories items in wordpress
- Customize search page
- Customise search page depending on result
- How do I make search only search in post content?
- How do I use a block to display search results?
- How to make search include data from wp_postmeta?
- Use “search” in permalink?
- Can I change the default search behavior “OR search” to “AND search”?
- Risk of sql injection for custom search form
- Filter post_type thumbnail in Search result
- Home page shows recent post, serps rank post within homepage
- Knowledge base high performance Live Search
- How to set empty search to load homepage template and not index.php
- custom search results affected by _REQUEST set
- How to implement search suggestions into search bar?
- Modifying post content with the_post action hook
- Trying to remove plural ‘s’ from search Query but it’s just removing every letter of the end – what am I doing wrong? Thanks
- Limit search to a specific folder in website
- Blog search just returns to front page (not search results!)
- Why is this search form not submitting when button is clicked?
- Search within table?
- How to insert meta keyword to search result page
- Custom search Dashboard widget
- Disable character’s replace in search
- WordPress Search Form Issue | Misleading search URL. | Pointing to wrong URL
- Echoing home_url() returns current url in searchform.php
- Exclude posts with certain meta data from search results
- Remove Page Timestamp via functions.php so it doesn’t show in Google Search Result Description [closed]
- Use pre_get_posts to display search results by meta in specific order
- Prevent search query from taking place when using Google CSE?
- Site Title in my Search URL
- I want empty search returns to home page in my wordpress
- Prevent searches less than 4 characters
- Changing search terms results a 403 – dsIDXpress Pro plugin [closed]
- Search wordpress using three different drop down menus
- How to get search result as image rather than page
- Search results – 404 error after hitting enter
- Redirect wordpress search query if its a tag
- Is it possible to show subdomain posts in main domain search result?
- Replacing word in wordpress Search not working Properly
- How to add search box to table results in admin page [closed]
- How might I go about using the API to search for a user by email, but ensuring that it is an exact match?
- Add CPT to search results with pre_get_posts
- Replacing wordpress search with custom code
- Use WordPress search in external static website
- Change output URL Search module
- How to show custom post type by either single meta_value or multiple meta_value(s) using WP_Query?
- search for single meta_key with numeric array of meta values
- How to customize default wordpress search query
- Customizing Google’s Search box in WordPress [closed]
- Insert DIV container below 1st search result
- I’ve messed up the admin search functionality. Help!
- Extend search function with link to searched word
- Content instead Excerpt on term
- Custom search results page not showing excerpt
- Search for Author and Custom Post Type
- Search page isn’t returning any results
- Error when searching without any results
- Listing parent section in search results
- Search results: How to add direct jump to anchor?
- Limit search to posts and pages
- Adding attributes to the core search block form
- How make Autocomplete with wp_query in post_type attachment
- WordPress Search – Reject partial matches
- Wp query search built out of 4 terms?