WordPress.org

Ready to get started?Download WordPress

Forums

%tag% in permalinks doesn't work (5 posts)

  1. amplifiedshock
    Member
    Posted 4 years ago #

    Hello,

    I tried adding the %tag% to my custom permalink but it does not work. The URL will not show the tag, but %tag%. For example: http://www.website.com/%tag%

    Everything else such as %category% seems to work.

    Any help would be much appreciated.

  2. Samuel B
    moderator
    Posted 4 years ago #

    http://codex.wordpress.org/Using_Permalinks#Choosing_your_permalink_structure

    you can't use %tag% in your permalinks but can use it as the category base

  3. amplifiedshock
    Member
    Posted 4 years ago #

    That article seems to indicate that %tag% is an option for permalinks.

    To test this theory out, I MANUALLY typed the permalink with the tag in my browser and it worked perfectly.

    For example:

    My custom structure: /%year%/%category%/%tag%/%postname%
    Sample tag: hockey
    Sample category: sports

    The URL will than look like: http://www.website.com/2009/sports/hockey/chicago-blackhawks-win

    When I access this in the browser, it works fine.

    HOWEVER, when I click it from the blog, it returns this link: http://www.website.com/2009/sports/%tag%/chicago-blackhawks-win

    This obviously means the %tag% permalink works; it's just that WordPress isn't linking to it properly.

    Any help would be much appreciated!

  4. _glook
    Member
    Posted 4 years ago #

    I'm actually having this issue, too. Since it works otherwise fine EXCEPT for permalink generation, I figured it's got to be something wrong in the permalink generation, and this is the (hacky) thing I ended up doing (this is WP 3.0):

    Go to /wp-includes/link-template.php

    Go to the function "get_permalink". in the array $rewritecode, add another entry of '%tag%' at the very end. You will also have to add a corresponding entry at the end of $rewritereplace. Before that array is declared, I did:

    $post_tag_name = get_the_tags($post->ID);
        if (!empty($post_tag_name))
        {
            foreach($post_tag_name as $tag)
            {
                $post_tag_name = $tag->slug;
                break;
            }
        }

    And then at the end of $rewritereplace, I added $post_tag_name.

    I presume you can do the same thing for custom taxonomies.

    This is pretty hacky, but it works. Ideally, this should be a plugin, but I don't care enough right now to do it right.

  5. thelaw
    Member
    Posted 4 years ago #

    Yes... this is a problem I have discovered as well.

    I have to use tags because WordPress refuses to use anything but nested categories for permalinks. No way to just use your primary category for permalinks like many blogs/newspapers do, e.g. times.co/hockey and times.co/football and instead it will put permalinks in as times.co/hockey/blackhawks/postname etc. It just gets far too long and there is no ability to edit slugs so you can have a long visual name and short slug. Very, very bad system in 3.0. Dumbing down the slugs is a poor idea and an error message after validation would be fine like "the slug you are using is being used for another category."

Topic Closed

This topic has been closed to new replies.

About this Topic