Your code is fine, I just tested it.
Consider the following: Sometimes you may have a blog and you want URLS to beset up like .xyz/DATE/POSTNAME
or perhaps you have a picture website and want it to be .xyz/category/image
.
Luckily, WordPress has built-in functionality to handle this. They are known as Permalinks
– you just need set yours up in the desired manner.
To do this, go to the WP admin menu -> settings -> permalinks
Then at the bottom, select ‘custom structure’ and enter /%category%/%postname%/
in the box. When you assign multiple categories to a post, only one can show up in the permalink.
To get around this, we can use the %
symbols tells WordPress that this part of the URL is interchangeable.
Then hit save and try to load a post.
For more information on Permalinks, see here.