How to make Tag Aliases

How would I build something like this with wordpress. Where multiple tags texts all go to the same page.
enter image description here

If you click on the tag “scifi” it takes you to tag “science fiction”. I am not looking for a way to merge them.

Read More

I want the tag text to vary, but the end page to be the same. Any Ideas?

A physical redirect shouldn’t be needed. The tag text of X needs to be linked to Y when wordpress builds the link.

Example: If I type “scifi” as a tag, and the link gets build as
<a href="/tag/science fiction">scifi</a> and therefore the tag is an alias for “science fiction”.

Where would I hook in to do this?

Related posts

Leave a Reply

3 comments

  1. Have not tested tested yet, but I see in the Codex page for wp_insert_term there’s one argument alias_of, which is described:

    There is no default, but if added, expected is the slug that the term
    will be an alias of. Expected to be a string.

    Maybe it helps 😉

  2. I can use the term_link filter, for the linking half of this problem:

    Here is a basic,still hard coded, version:

    <?php
    /*
    Plugin Name: Tag Alias
    Version: 0.001
    Plugin URI: 
    Description: Adams Tag Alias -> hard coded tag redirects
    Author: Adam
    */
    
    $aliases = array (
        "450"  => "400",
        "speed controler" => "esc",
        "kds" => "esc"
    );
    
    function tagAliasFilter ($termlink, $term, $taxonomy) {
        global $aliases;
        foreach ($aliases as $alias => $key)
        if($term->slug == $alias)
        {
            $termlink = str_replace($alias,$key,$termlink);     
        }   
        return $termlink;
    }
    add_filter('term_link', 'tagAliasFilter',10,3);
    ?>
    

    Now what is missing is pulling in the aliases on the tag pages