Dynamic permalinks in WordPress

The WordPress permalink system can be adapted very well to your own needs with the help of structure tags . The setting% postname% is probably the most common and practicable solution. However, if you want to implement real dynamic links, you first have to expand the system with your own code.

The powerful WordPress Rewrite API offers many options for adapting the system to your own requirements. If you want complete freedom, WordPress is configured in such a way that any URLs (with any number of levels) are possible. As a result, for example, the call to


the output

   [0] => "dies"
   [1] => "ist"
   [2] => "eine"
   [3] => "individuelle"
   [4] => "url"

To achieve the desired behavior, we use the actions "rewrite_tag" and "rewrite_rule" and add the following code to the functions.php file of the active theme:


Afterwards it is mandatory to save the permalink settings again (Settings > Permalinks > Apply changes or alternatively the one-time call of the function flush_rewrite_rules ()) to make the new rules work. Finally we create a new page with the permalink "rewrite" and the template "rewrite-page", which has to be created first by the following file:


In the standard configuration, all URLs are accessed. The $ base variable can also be equipped with any nested subfolders: The value "pop / up" enables the URL to be accessed, for example


All other URLs are unaffected - these are processed by WordPress as usual.