This simple code modification will open all external links in a new window or tab, depending on your browser's configuration. This modification is useful to prevent users from navigating away from the wiki when they click an external link. External links are defined as any link that leaves the Wiki (even if they are on the same server).

Note: This modification also requires XHTML Transitional. XHTML Strict is not supported, since the target attribute is not allowed. If you don't understand this and/or haven't modified the DOCTYPE in actions/header.php, then you don't need to worry about this.

Step 1 for Wikka version =1.1.6.6


Locate this line in the source:

           $result = '<a class="'.$class.'" href="'.$url.'">'.$text.'</a>';


In Wikka version 1.1.6.6, you can find the code in libs/Wakka.class.php at line 1050.

Replace it with this:

   $external_link_new_window = $this->GetConfigValue("external_link_new_window");
    if ($external_link_new_window = "0") {
            $result = '<a class="'.$class.'" href="'.$url.'">'.$text.'</a>';
    } else {
            $result = '<a class="'.$class.'" href="'.$url.'" target=\"_new\">'.$text.'</a>';
    }



Step 1 for Wikka versions <1.1.6.6


Locate this line in the source:

        return $url ? "<a class=\"ext\" href=\"$url\">$text</a>$external_link_tail" : $text;


In Wikka versions <1.1.6.2, you can find the code in wikka.php, somewhere around line 662.
In Wikka versions >=1.1.6.2, you can find the code in libs/Wakka.class.php, somewhere around line 882.

Replace it with this:

               $external_link_new_window = $this->GetConfigValue("external_link_new_window");
                if ($external_link_new_window = "0") {
                        return $url ? "<a class=\"ext\" href=\"$url\">$text</a>$external_link_tail" : $text;
                } else {
                        return $url ? "<a class=\"ext\" href=\"$url\" target=\"_new\">$text</a>$external_link_tail" : $text;
                }


Step 2


Then add the following element to the wikka.config.php wakkaConfig array:

'external_link_new_window' => '1'


'0' (zero) turns off opening external links in a new window. Any non-zero value turns on opening external links in a new window.

That's all there is to it. --JasonHuebel

TODO:

CategoryUserContributions
Comments [Hide comments]
Comment by EmeraldIsland
2008-01-19 12:06:14
In case you want to build a 100% XHTML 1.1 strict website based on WikkaWiki, you have to forget target attribute for your links. Target is available in XHTML 1.0 transitional.
(There is very few changes to do to make Wikka 1.1.6.3 wiki 100% XHTML 1.1 strict)
Comment by JasonHuebel
2008-01-24 20:44:51
Removing the target attribute makes this modification pointless. Since no version of XHTML/HTML Strict includes a target attribute. Transitional has to be used in order to use the target attribute. The only other option would be using a Javascript onclick event for each external link, which over-engineers the problem and adds unnecessary bloat to the page.
Comment by ToddMurtha
2008-08-13 18:38:36
In version 1.1.6.5 I found the code at line 1018.. Great mod.. Thanks.
Comment by GamblingPedia
2009-08-26 08:53:06
Nice mod, thanks. But a little fix to make it XHTML Valid

replace:

$result = '<a class="'.$class.'" href="'.$url.'" target=\"_new\">'.$text.'</a>';

with:

$result = '<a class="'.$class.'" href="'.$url.'" target="_new">'.$text.'</a>';


And, a little SEO mod if you dont want Google to follow an external links:

$result = '<a class="'.$class.'" href="'.$url.'" target="_new" rel="nofollow">'.$text.'</a>';

(use with caution! If google finds all external links with nofollow, the penalty will be given)
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki
Page was generated in 0.0709 seconds