Auto-hyperlink text URLs in post content and comment text to the URL they reference. Does NOT try to hyperlink already hyperlinked URLs. Improves upon WordPress’s default make_clickable function, along with adding some configuration options (such as link truncation).
This plugin seeks to address certain shortcomings with WordPress’s default auto-hyperlinking function (make_clickable()) (which itself was borrowed from phpBB). This tweaks the pattern matching expressions to prevent inappropriate adjacent characters from becoming part of the link (such as a trailing period when a link ends a sentence, links that are parenthesized or braced, comma-separated, etc) and it prevents invalid text from becoming a mailto: link (i.e. smart@ss) or for invalid URIs (i.e. blah) from becoming links. In addition, this plugin adds configurability to the auto-hyperlinker such that you can configure:
– If you want auto-hyperlinked text URLs to only show the hostname
– If you want auto-hyperlinked text URLs truncated after N characters
– If you want auto-hyperlinked text URLs to open in new browser window or not
– Text to come before and after the link text for truncated links
This plugin will recognize any protocol-specified URI (http|https|ftp|news)://, etc, as well as e-mail addresses. It also adds the new ability to recognize Class B domain references (i.e. «somesite.net» where not just those prepended with «www.») as valid links (i.e. «wordpress.org» would now get auto-hyperlinked)
- Download the file autohyperlink-urls.zip and unzip it into your /wp-content/plugins/ directory.
Copy and paste the the code ( autohyperlink-urls.phps ) into a file called autohyperlink-urls.php, and put that file into your /wp-content/plugins/ directory.
- Optional: Modify any configuration options (presented as defaults for the arguments to the function hyperlink_urls())
- Activate the plugin from your WordPress admin ‘Plugins’ page.
function c2c_hyperlink_urls ($text, $mode='0', $trunc_before='', $trunc_after='...', $open_in_new_window=true)
- $text : The text to search for plain-text URLs which should be hyperlinked
- $mode : How the text part of the newly created hyperlinks should appear. Assume as an example «http://wordpress.org/support/10»
- 0 = The full text of the URL (ie. «http://wordpress.org/support/10»)
- 1 = Host-only (ie. «http://wordpress.org»)
- 11+ = (Any number greater than 11 will result in only that many characters appearing in the link.)
- $trunc_before : Text/HTML to appear before each link created when $mode is 0 or 11+ and truncation occurs
- $trunc_after : Text/HTML to appear after each link created when $mode is 0 or 11+ and truncation occurs
- $open_in_new_window : Boolean value (either ‘true’ or ‘false’) to determine whether all created hyperlinks should open a new window when the link is clicked by a visitor; default is ‘true’.
«wordpress.org», appearing un-hyperlinked in post text or comment text, becomes:
<a href=»http://wordpress.org» title=»http://wordpress.org» target=»_blank»>wordpress.org</a>
Assume the following text appears in a post/comment: «http://www.somesite.org/with/a/very/long/url/that/may/break/your/sites/layout»
$mode = 1, $trunc_before='[‘, $trunc_after=’]’
- WordPress Support Forum announcement for Auto-hyperlink URLs
- 10 Oct 2004 : v2.01 — Fix to once again prevent linking already hyperlinked URL
- 27 Sep 2004 : v2.0 —
- Plaintext URLs can now begin, end, or be all of the post and it will get auto-hyperlinked
- Incorporated some WP1.3 regular expression changes to
- Added «gov» and «edu» to the list of common domain extensions (for Class B domain support)
- No longer displays the protocol (the «http://» part) in the displayed link text
- Dropped support for auto-linking aim: and icq:
- Prepended function names with «c2c_» to avoid potential future conflict with other plugins or the WordPress core
- Changed license from BSD-new to MIT
- 13 Jul 2004 : v1.01 — Slight tweak to prevent blah from becoming a link
- 13 Jul 2004: v1.0 — Complete rewrite
- 08 Jul 2004 : v0.9 — Released to the public
Copyright (c) 2004 by Scott Reilly (aka coffee2code)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the «Software»), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED «AS IS», WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.