Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've looked around and around for a good WordPress plugin. I know this is a shopping question, but such an important aspect of managing your WordPress blog, I'm surprised to find that there isn't a more standard selection. Specifically, I need a plugin to help with:

  • Set rel="nofollow"
  • Open outgoing links in new tab/window
  • Bulk processing
  • Well-maintained

What do you use?

share|improve this question
    
As in, the links in your post content? Or links elsewhere? –  m0r7if3r Apr 2 '12 at 17:48
    
Yes, good question. It would be nice if the plugin allowed me to specify based on content sections -- post, sidebar, footer. But that might be asking to much. –  keruilin Apr 2 '12 at 17:50
    
As in: you want to be able to control every link on your site from a single page? –  m0r7if3r Apr 2 '12 at 18:20
    
oh yea, that would be sweet –  keruilin Apr 2 '12 at 18:29
add comment

2 Answers

up vote 1 down vote accepted

I can think of two methods to accomplish this, either would be equally valid. I will cover the pros and cons of each at the end of the explanation for them.

  1. Use a Shortcode

    Define a shortcode, say [wpse47706_link]. You will probably want to give it an href attribute. Use this for every single link on your site, internal and external. When you go to output the actual text, parse the url (parse_url()) and get the hostname. Compare this to the site url. If it matches, apply one set of rules, otherwise apply another. You could control these from your dashboard if you felt so compelled (that's settings API, a whole different topic).

    pros

    • efficient with resources
    • global control is easy

    cons

    • does not afford individual control
    • control over links from varying regions could become tricky, especially if you want to dynamically generate the settings areas
  2. Parse the site's content

    By parsing the content of the entire site, you can get every link on the site. You would have to figure out what you do and don't want to parse, and probably do a lot of background work...which could become rather unpleasant. When you have all the content of the site, parse it for links (with a regex) and output these. Due to the method by which they are gotten it will be relatively simple to organize them by location on the site, even down to the level of links in an individual post or widget. Once you have gotten all of these, you can modify them (and then subsequently overwrite them in the source) to your liking. This could be done from some sort of admin interface with checkboxes and such, or programatically based on a set of rules you define.

    pros

    • much finer control, down to the individual link level
    • output of links is more efficient (since it requires no PHP, as the modifications are made directly to the db)

    cons

    • directly modifying content (generally a bad idea)
    • if you have lots of links, the UI could become difficult to manage
    • I can imagine the load for the management page becoming rather heavy
    • The changes could be overwritten by an author
    • does not allow control over links not stored in the db (whereas, through do_shortcode(), the other method does)

Hopefully this has given you something to consider...neither is really an outstanding option, but I wouldn't say either is bad. Personally I would go with the shortcode, but that's me.

share|improve this answer
add comment

For the scope you define it's a matter of defining the correct filters although the title "managing outbound links" is much wider.

For your scope:

a) setup your range of filters e.g. "replace in post content" : the_content : see http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content (but also see bookmark_list, comment_text, get_comment_author_link, widget_text, etc... for other places to filter)

b) define a regex to search for outgoing links e.g.:

const HTML_REF_REGEX2 = '/<a(.*?)href=[\'"](.*?)[\'"](.*?)>(.*?)<\\/a>/i';

c) from the filter call a function that preg_replace_callback's the found uri's e.g. with

$r_content = preg_replace_callback(self::HTML_REF_REGEX2,
                array($this,'DoStuffToToUri'), $content);

d) in DoStuffToUri do whatever you want to the external links e.g. : add no follow, add _blank, place a favicon in front of each link and whatever and "rebuild" the outgoing link with what you have added e.g. :

return '<a' . $arrUrlMatches[1] . 'href="' . $arrUrlMatches[2]
                . '"' . $arrUrlMatches[3] .'>' . $arrUrlMatches[4] . '</a>';

However... "managing outgoing links" would mean much more than just adding simple filters: you would want a browsable list of all outgoing links incl. HTTP status returns and possible redirections, their value in terms of facebook links, tweets, google likes, pr, alexa rating and so on, automatic disabling of 404's, the location from where it is called so you can click and edit the outgoing url, etc...

p.s. when validating your outgoing links , you want want to check for the protocol since there will probably be lots of typos e.g.:

if (!((substr($str_original_uri_uri,0,7) == 'http://' ) ||
                  (substr($str_original_uri_uri,0,8) == 'https://') ||
                  (substr($str_original_uri_uri,0,7) == 'file://' ) )
                )
            {
                return false;
            }

and the stuff inside the "text" area of the outgoing link (if you want to change stuff inside the "content" of the outgoing link (can be weird stuff) e.g.:

if (strstr(trim($str_original_uri_display_text), '<'))
            {
                return false;
            }

you might also want to exclude certain file types e.g.:

$str_original_uri_type_extension
                = EdlUtils::GetUriExtension($str_original_uri_uri, '.', 1, 1);
            if ($str_original_uri_type_extension != false)
            {
                if (stristr($this->mStrNotAllowedExtensions,
                    $str_original_uri_type_extension) != false)
                {
                    $bool_href_valid=false;
                }
            }

You might also want to log the ones that are excluded so they can be "corrected" if needed.

p.p.s. bits of code for replacing: http://plugins.svn.wordpress.org/wp-favicons/trunk/includes/server/class-metadata.php

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.