wordpress custom rewrite rule

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

speaking url I want looks like this: domain/the-brand/xyz

Read More

domain/?pagename=brand-2&brand=xyz is the working url…

i added already a custom 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 an error:

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);

Related posts

2 comments

  1. It looks like you’re doing the right thing, you’ll just want to refresh your permalinks as noted here

    Note that these rules are usually called inside the init hook.
    Furthermore, permalinks will need to be refreshed (you can do this
    from your admin under Settings > Permalinks) before the rewrite
    changes will take effect. Requires one-time use of flush_rules() to
    take effect. See also Flushing Rewrite on Activation.

  2. try this:

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

Comments are closed.