Custom Wordpress Rewrite Rule

I'm trying to get a custom rewrite rule to work, but it doesn't work at the moment. maybe someone can help?

talking url I want to look like this: domain/the-brand/xyz

domain/?pagename=brand-2&brand=xyz

- working url ...

I have already added my own tag to functions.php:

function custom_rewrite_tag() {
  add_rewrite_tag('%brand%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);

      

and a custom rule, but there seems to be a bug:

function custom_rewrite_rule() {
    add_rewrite_rule('/the-brand/([^/]*)' , 'index.php?pagename=brand-2&brand=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);

      

+3


source to share


2 answers


It looks like you are doing the right thing, you just want to update your permalinks as mentioned here



Note that these rules are usually called inside the initialization hook. Also, you need to update the permalinks (you can do this from your admin in Settings> Permalink) before the overwrite changes will take effect. Requires one-time use of flush_rules () to take effect. See also Flushing Rewrite on Activation.

0


source


try this:



add_rewrite_rule ('^ the-brand / ([^ /] *) /?', 'index.php? pagename = brand-2 & brand = $ matches [1]', 'top');

0


source







All Articles