Using add_rewrite_rule() to redirect to Front Page

Found the solution in this thread: How to prevent the default home rewrite to a static page Just disable canonical redirect for front page: function disable_canonical_redirect_for_front_page( $redirect ) { if ( is_page() && $front_page = get_option( ‘page_on_front’ ) ) { if ( is_page( $front_page ) ) $redirect = false; } return $redirect; } add_filter( ‘redirect_canonical’, … Read more

How to change the matches in add_rewrite_rule

Rewrite rules don’t call functions like you’re asking. WordPress is far more flexible than that, because you might want to run your code at any one of an unlimited set of points in the processing of the page and not be restricted to that one specific moment in the code when the rewrite rule is … Read more

add_rewrite_rule with bottom priority doesn’t handle the WordPress pages

When you point a rule to anything other than index.php, it gets interpreted as external and written to the .htaccess file. After external rules are parsed, requests get directed to WordPress, which parses the internal rules in php. This is the internal version: function custom_rewrite() { add_rewrite_rule( ‘^(bar|baz|foo-.*)’, ‘index.php?my_var=$matches[1]’, ‘top’ ); } add_action( ‘init’, ‘custom_rewrite’ … Read more

Rewrite rule for admin-ajax.php

There are a few things to sort out here. The first is why your rewrite rule will not work. add_rewrite_rule(‘/api’, ‘/wp-admin/admin-ajax.php’, ‘top’); The WordPress rewrite does not redirect to a page. What does is it parses the path using regular expressions into a WordPress query vars. If you disable pretty URLs in WordPress, you’ll see … Read more

Rewrite loading custom template file but is_home() returns true, and there’s no 404

Conditional variables are based on the main page query ($wp_query). If you want is_home() to be false, then you need to manually set it to false ($wp_query->is_home = false) or override the main query such that it’s not true anymore. Probably you’d do that in your template_redirect_intercept function there, or in the individual page templates … Read more

Redirect taxonomy to custom template to list terms in taxonomy

The 404 might be created because your regular expression requires the value after ‘state/’. Please try to replace: function handle_taxonomy_route() { add_rewrite_rule(‘^state/([^/]+)/?’, ‘index.php?state_var=$matches[1]’, ‘top’); } with: function handle_taxonomy_route() { add_rewrite_rule(‘^state/([^/]*)/?’, ‘index.php?state_var=$matches[1]’, ‘top’); }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)