Best way to trigger rewrite rules

init is the recommended hook and no, the rewrite rules will not be overwritten each time the hook fires or that the page is loaded, unless if you call flush_rewrite_rules() or WP_Rewrite::flush_rules() in your callback. add_action( ‘init’, ‘add_my_rewrite_rules’ ); function add_my_rewrite_rules() { add_rewrite_rule( … ); flush_rewrite_rules(); // don’t do this } So please don’t do … Read more

URL renaming issue

When I go to www.riyachting.com, I get redirected to riyachting.com. Some browsers remove the fragment (part after the #) of the URL in this redirect. Chrome keeps the original fragment and the lightbox works. Safari removes it and the lightbox doesn’t work. So either use the final URL in your link, or use something else … Read more

Requested URL changes when using custom rewrite rule

this: add_rewrite_rule( ‘membership/member-profile/([^/]+)/?$’, ‘index.php?pagename=member-profile&profile=$matches[1]’, ‘top’ ); should be: add_rewrite_rule( ‘membership/member-profile/([^/]+)/?$’, ‘index.php?pagename=membership/member-profile&profile=$matches[1]’, ‘top’ ); the difference is pagename should contain the parent/child path. also- if profile isn’t a recognized query var, it needs to be added in order to be accessed: function wpse47596_query_vars( $query_vars ){ $query_vars[] = ‘profile’; return $query_vars; } add_filter( ‘query_vars’, ‘wpse47596_query_vars’ );

Using WP Rewrite to rewrite custom urls in this scenario

In your case would be something like: add_action(‘rewrite_rules_array’, ‘rewrite_rules’); function rewrite_rules($rules) { $new_rules = array( ‘product/([0-9]+)/?$’ => ‘index.php?product=$matches[1]’ ); return $rules + $new_rules; } add_action(‘query_vars’, ‘add_query_vars’); function add_query_vars($vars) { array_push($vars, ‘product’); return $vars; } add_action(‘template_redirect’, ‘custom_template_redirect’); function custom_template_redirect() { global $wp_query, $post; if (get_query_var(‘product’)) { include(YOURPLUGINDIR . ‘templates/product_template.php’); exit(); } } In product_template.php, you can … Read more

htaccess rewrite ignored

Assuming pretty permalinks are enabled in settings, WordPress does attempt to add set of rules to the .htaccess. In a nutshell their logic is to route anything that isn’t existing file/directory to WP’s index.php. After that WP is loaded and tries to interpret URL via its rewrite configuration and other data. This does not exclude … Read more

Flush rewrite rules on option update with Settings API

I register custom post type on init action and the validate which I’m writing about is set to register_setting inside admin_init action. This is the key to your issue. You’re registering the custom post type, and presumably you’re setting up the rewrite rules in that registration. When you call flush_rewrite_rules(), the rules are rebuilt right … Read more

Adding a rewrite rule to page that has no fixed variables and pagination

Got it to work, changing the regex from (.+) to (.*) Maybe helpful for others searching same rewrite on search and pagination. add_rewrite_rule(‘discover/interiors/interior-results/(.*)/page/([0-9]{1,})/?’, ‘index.php?pagename=discover/interiors/interior-results&tag1=$matches[1]&paged=$matches[2]’, ‘top’ ); add_rewrite_rule(‘discover/interiors/interior-results/(.*)’, ‘index.php?pagename=discover/interiors/interior-results&tag1=$matches[1]’, ‘top’ );

How to get default permalink link text?

When you are editing a post you can notice the URL in your browser looks like http://***.com/wp-admin/post.php?post=1351&action=edit The number in the URL corresponds to the ID of your post. So you can access your post with that ID. In this example the short link for the post would be http://***.com/?p=1351 When a visitor browsers this … Read more

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