Rewriting / Redirecting request outside wordpress

Normally, to add rewrite rules in WordPress there is the generate_rewrite_rules filter. From there you can call the function add_external_rule ($wp_rewrite->add_external_rule($rule)) where you could add your rule which not maps to index.php. Unfortunately WordPress will try to write this rule into the .htaccess file. But maybe this could be helpful.

How to add gallery slug to attachment url?

So I was able to make it work (without .htaccess as Tom sugested) using WordPress Rewrite API. Here is my working code (from functions.php): function add_rewrite_rules( $wp_rewrite ) { $new_rules = array ( ‘(the-gallery-slug)\/(.?.+?)(?:/([0-9]+))?/?$’ => ‘index.php?pagename=$matches[2]’ ); // Always add your rules to the top, to make sure your rules have priority $wp_rewrite->rules = $new_rules … Read more

Pretty Filter URL

Here is my current code: function hm_base_date_query_vars($vars) { $vars[] = ‘base_date’; return $vars; } add_filter(‘query_vars’, ‘hm_base_date_query_vars’); function hm_base_date_rewrite_rule() { add_rewrite_rule( ‘^my-calendar/([^/]*)/?’, ‘index.php?pagename=my-calendar&base_date=$matches[1]’, ‘top’ ); } add_action(‘init’, ‘hm_base_date_rewrite_rule’, 10, 0); $base_date_test = get_query_var(‘base_date’); on the url example.com/my-calendar/foo my var $base_date_test returns null Maybe someone can help me. Thanks. // Edit: It works. I tried to call … Read more

Dynamic content and rewrite URLs

I would suggest the use of the Insert PHP plugin: https://fr.wordpress.org/plugins/insert-php/ You would have to bind the URL path as a $_GET parameter in the .htaccess using RewriteCond/RewriteRule (if you want to keep your URL structure) or use a structure that is something like domain.com?city=New York. In your WordPress post, you’d be able to include … Read more

Need help adding rewrite rules to page

You Can follow below step : 1) Login to wp-admin 2) Goto the setting in sidebar menu Into permalinks 3) “Common Settings” In select the Post name and “Product Permalinks” automatically set like /product/sample-product/ I hope it’s useful.

Custom post type rewrite and wp_pagenavi interfering with each other

I solved it. To enable the new rule, save the parmalink structure. Ive tried to follow the example with news from above. function news_page_rewrite_rule() { // Get the URL of the page listing out the news. // Here I use the Advanced Custom Fields plugin. $news_page_url = get_field(‘_news_page’, ‘options’); if (empty($news_page_url)) return; // Get the … Read more