I have created page-images.php, inside that file I have some code with Template name, in dashboard I have created page Slike and chose that template... all that is working.

I have added rewrite rule just as it is described here and I have flushed permalinks https://codex.wordpress.org/Rewrite_API/add_rewrite_rule

function pl_add_rewrite_rule() {
add_action('init', 'pl_add_rewrite_rule', 10, 0);

Now these urls work:

  • localhost/mysite/slike
  • localhost/mysite/slike/biljke/cvijece

But this doesn't

  • localhost/mysite/slike/biljke

In Codex it says that capture groups are optional. Do I have to do something else to make it work? I want to have all 3 kinds of urls working

(string) (required) A regular expression to match against a requested URL.
 This can optionally use one or more capture groups.
  • 1
    what is optional is the use of capture groups not the catching in the regex. you can us this website to construct the regex you need : regex101.com
    – mmm
    Sep 16 '16 at 22:10

Ok after 4 hours I managed to make it work

function pl_add_rewrite_rule() {
    // this works with pagination too

add_action('init', 'pl_add_rewrite_rule', 10, 0);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.