Support » Everything else WordPress » How to show tag name in URL

Viewing 2 replies - 1 through 2 (of 2 total)
  • An issue with doing this is that WordPress might not understand how to process
    ‘mytagname’. It could be a tag, some other taxonomy or even a page/post slug.

    If there is a way to clearly differentiate tags via a regular expression, you can use the add_rewrite_rule() function to set this up where all URL paths matching /[a-z]+ would be rewritten to tag/[a-z]+.

    There are examples at the bottom of the docs. You will need to flush permalinks for the changes to take effect.

    • This reply was modified 1 week, 4 days ago by dhruvkb.

    To achieve this, I had to add the following lines to functions.php. You could create a child theme to preserve these changes across theme updates.

    add_action('init',  function() {
        add_rewrite_rule('^([a-z]+)[/]?$', 'index.php?tag=$matches[1]', 'top');
    });

    Then I changed the other permalinks in Settings > Permalinks to ensure that none of them matched this regex ^([a-z]+)[/]?$ and clicked Save Changes to flush the record.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.