Support » Your WordPress » I want to add tag to my links in WordPress

Viewing 12 replies - 1 through 12 (of 12 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    You could create a simple plugin to do this sort of thing easily enough. Probably a plugin like this already exists. Try searching around a bit.

    Thread Starter cashbagg

    (@cashbagg)

    Been searching for a while. no luck yet….

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Well, if you want to roll your own plugin, you need to understand filters.

    A filter receives some text, modifies it, and returns it. So something like this would do the job:

    function adjust_links($content)
    {
    // use regular expressions to modify $content here
    return $content;
    }
    add_filter('the_content','adjust_links');

    Your function would then be called every time a post is displayed, and it would contain the content of the post. So you could add code to find and modify your links accordingly.

    Wow Otto – you just saved me a LOT of trouble with an old time client. Thanks so much for your input on this board.
    So easy, also. :>)

    Thread Starter cashbagg

    (@cashbagg)

    🙁 way out of my league.

    Thread Starter cashbagg

    (@cashbagg)

    otto:

    can u specifically tell me how i integrate http://hornyoyster.com/test/out.php?l= before my url’s?

    where do i stick this in the code u posted?

    Thread Starter cashbagg

    (@cashbagg)

    like this?

    function adjust_links($content)
    {
    // http://hornyoyster.com/test/out.php?l=
    return $content;
    }
    add_filter(‘the_content’,’adjust_links’);

    ?>

    (ps. i created a plugin with this code, and didn;t do anything)

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    No, you would need a preg_replace function there to do the adjustment to the content. Something like this:

    function adjust_links($content)
    {
    $content = preg_replace ("href=\"(.*)\"","href=\"http://hornyoyster.com/test/out.php?l=%{1}\"",$content);
    return $content;
    }
    add_filter('the_content','adjust_links');

    This is just an example. While it may work, it certainly won’t handle every case, and you should really use a better regular expression than my quick attempt. Consult a regex guru.

    Thread Starter cashbagg

    (@cashbagg)

    bumping old post…still haven’t gotten a solution.

    anyone?

    I use Simple Tagging for my tagging on my blog. I like it a lot, very simple to use, and you can create a tagging cloud on your site as well.

    You can look at my blog for VistaDB for an example of how it works here

    Thread Starter cashbagg

    (@cashbagg)

    I had a look at that plugin, and I’m not sure it does what I need. (I’m not sure what it does at all actually).

    Can it add my tracking code to every url?

    cashbagg….using the term “tag” confused matters a bit…jasonshortphd is talking about “tagging” and “creating a tag cloud” as a method of grouping similar posts together, using tags, or keywords. The plugin he referred to accomplishes that.

    But you’re looking for a way to prepend affiliate code to all your http links. Quite a different matter. Maybe you should try Googling for a WP plugin designed for affiliate links? I don’t know of one, but there is probably something out there.

    You might also give aLinks a shot. I don’t know if it’s working with 2.1 or 2.2, but it used to be a great way to automatically “linkify” any specific words in your post. It might indirectly accomplish what you’re trying to do, if there is no alternative readily available.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘I want to add tag to my links in WordPress’ is closed to new replies.