Created
August 10, 2017 18:05
-
-
Save jamesmorrison/8018ecabbf19c132886c5d7a7d8ee242 to your computer and use it in GitHub Desktop.
Rewrite search URL's to "pretty" permalinks. A custom permalink structure must be set.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* Plugin Name: Rewrite Search URL's | |
* Description: Rewrite search URL's to "pretty" permalinks. A custom permalink structure must be set. | |
* Version: 1.0.1 | |
* Author: James Morrison | |
* Author URI: https://www.jamesmorrison.me/ | |
* | |
**/ | |
add_action( 'template_redirect', function() { | |
// Ensure a permalink structure is set and this is a search results page request | |
if ( ! empty( get_option( 'permalink_structure' ) && ! empty( $_GET[ 's' ] ) ) ) { | |
wp_redirect( esc_attr( home_url( '/search/' . urlencode( get_query_var( 's' ) ) ) ), 302 ); | |
exit(); | |
} | |
}, 10, 0 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment