Rewrite permalink function

And add option to enable/disable