Great plugin! Implemented within minutes and simple for end users to manage.
Client is particularly happy with the reporting features of the plugin.
BFowler for Ad King Pro

Latest Tweets

Ad King Pro has FINALLY has an update! A cleanup really with a few tweaks to a couple of features. More to come!
Your using Ad King Pro right? Your site is responsive, surely. Implement adverts so their mobile friendly!
Invoice King Pro and Ad King Pro both receive some amazing new features that you will want to know about!
Follow KingProPlugins on Twitter

Pretty permalinks for the search page

Most people should be using at least some form of pretty permalinking with their WordPress system. It should almost be set as a default these days given the way SEO is. Most would notice when pretty permalinks is enabled and you have a search page, that the URL doesn’t follow the rules. It seems to ignore everything around it and still runs off the “?s=%QUERY%” string.

I don’t know about you, but if I have the rest of the site using pretty permalinks, I want the search page to follow. SO, the simpliest way is more education for the wordpress system:

function kpp_change_search_url_rewrite() {
 if ( is_search() && ! empty( $_GET['s'] ) ) {
 wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
add_action( 'template_redirect', 'kpp_change_search_url_rewrite' );

The above does force a redirect, however it means that you don’t have to modify how the search is currently working in WordPress. If you didn’t want the redirect, I know the latest version of WordPress, when using a permalink structure, does the following by default so you can skip past the next 2 code examples. If your finding that your version isn’t, you could create a rewrite rule for this but you also need to modify the search form to point to “/search/” and process the search so that it exists in the URL. There is 2 ways you can go about that:

RewriteRule ^search/(.*)$ index.php?s=$1

This would go directly into the .htaccess file. Now there is a way to do the above without modifying the .htaccess file directly and thats by using the WP_Rewrite class to add the rule. Something along the lines of:

function kpp_rewrite_rules() {
 global $wp,$wp_rewrite;
 $wp_rewrite->add_rule('search/([^/]+)/', 'index.php?s=$matches[1]', 'top');
 $wp_rewrite->add_rule('search/([^/]+)/page/([^/]+)/', 'index.php?s=$matches[1]&paged=$matches[2]', 'top');
// Once you get working, remove this next line

This method is quite clean and leaves all modifications within the wp-content folder.

So now if you type into your browser yourdomain/search/keyword it should take you to your search page as normal. The trick is that the form needs to use the same structure. This would obviously require a custom search form and functionality to do so. If anyone has any input on that subject, please feel free to comment below 😉

Leave a Reply

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