WordPress.org

Ready to get started?Download WordPress

Forums

I want to add tag to my links in WordPress (13 posts)

  1. cashbagg
    Member
    Posted 7 years ago #

    I would like to know how to tag every link I create in wordpress. For example, in my post screen, I have a button called 'link' which i click on, and enter the hotlink info. Is there a way I can change to wordpress code to always have my link preceded by "http://hornyoyster.com/test/out.php?l="

    thx.

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    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.

  3. cashbagg
    Member
    Posted 7 years ago #

    Been searching for a while. no luck yet....

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    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.

  5. Samuel B
    moderator
    Posted 7 years ago #

    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. :>)

  6. cashbagg
    Member
    Posted 7 years ago #

    :( way out of my league.

  7. cashbagg
    Member
    Posted 7 years ago #

    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?

  8. cashbagg
    Member
    Posted 7 years ago #

    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)

  9. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    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.

  10. cashbagg
    Member
    Posted 6 years ago #

    bumping old post...still haven't gotten a solution.

    anyone?

  11. jasonshortphd
    Member
    Posted 6 years ago #

    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

  12. cashbagg
    Member
    Posted 6 years ago #

    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?

  13. kalico
    Member
    Posted 6 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags