Rewrite function

Go to Settings->Permalinks Add this to Custom Structure: /%postname%/ Update WordPress generates .htaccess-files for this. Just go to your root and activate the show invisable files on your computer. Here is the htaccess for the structure: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d … Read more

URL Variables in a Certain Page

Try this code: add_filter( ‘query_vars’, ‘my_query_vars’ ); function my_query_vars( $vars ) { $vars[] = ‘catname’; return $vars; } add_action( ‘generate_rewrite_rules’, ‘my_rewrite_rules’ ); function my_rewrite_rules( $wp_rewrite ) { $products_page_id = 1; //your product’s page ID $wp_rewrite->rules = array( ‘products/?([0-9]{1,})/?$’ => $wp_rewrite->index . ‘?page_id=’.$products_page_id.’&paged=’ . $wp_rewrite->preg_index( 1 ), ‘products/(.+?)/?([0-9]{1,})/?$’ => $wp_rewrite->index . ‘?page_id=’.$products_page_id.’&catname=”.$wp_rewrite->preg_index( 1 ).”&paged=’ . $wp_rewrite->preg_index( … Read more

Rewrite URL variable to custom path

You could add the path via add_rewrite_endpoint, then alter the query via the pre_get_posts action. Here’s a proof-of-concept example that alters the posts_per_page when domain.com/highest-rated/ is requested: // add the endpoint function wpa85664_add_endpoint(){ add_rewrite_endpoint( ‘highest-rated’, EP_ALL ); } add_action( ‘init’, ‘wpa85664_add_endpoint’ ); // check if the endpoint is in the current request // and alter … Read more

Overwrite URL on blog posts

If you are not using Custom Post Types the following in your permalink settings should work just fine. /blog/%postname%/ Screenshot (Below can still be applicable depending on your use of custom post types) Keep your regular permalinks on blog like you have it in settings. And in your custom post type arguments the “with_front” Boolean … Read more

URL Redirect in WordPress

For this kind of rewriting, I’m using this code (haven’t tested this one exactly, so may contain minor bugs): add_filter( ‘query_vars’, ‘binda_query_vars’ ); function binda_query_vars( $vars ) { $vars[] = ‘pp’; return $vars; } add_action( ‘generate_rewrite_rules’, ‘binda_rewrite_rules’ ); function binda_rewrite_rules( $wp_rewrite ) { $wp_rewrite->rules = array( ‘news/([0-9]{1,})/([0-9]{1,})/?$’ => $wp_rewrite->index . ‘?post_type=news’ . ‘&pp=’ . $wp_rewrite->preg_index( … Read more