WordPress.org

Plugin Directory

Auto-hyperlink URLs

Automatically hyperlink text URLs and email addresses originally written only as plaintext.

Examples

(when running with default configuration):

  • "wordpress.org"
<a href="http://wordpress.org" class="autohyperlink">wordpress.org</a>
  • "http://www.cnn.com"
<a href="http://www.cnn.com" class="autohyperlink">www.cnn.com</a>
  • "person@example.com"
<a href="mailto:person@example.com" class="autohyperlink">person@example.com</a>

To better illustrate what results you might get using the various settings above, here are examples.

For the following, assume the following URL is appearing as plaintext in a post: http://www.somelonghost.com/with/some/long/URL/that/might/mess/up/your/theme/and/is/unsightly.php

And unless explicitly stated, the results are using default values (nofollow is false, hyperlink emails is true, Hyperlink Mode is 0)

  • By default:
<a href="http://www.somelonghost.com/with/some/long/URL/that/might/mess/up/your/theme/and/is/unsightly.php" class="autohyperlink">www.somelonghost.com/with/some/long/URL/that/might/mess/up/your/theme/and/is/unsightly.php</a>
  • With Hyperlink Mode set to 1
<a href="http://www.somelonghost.com/with/some/long/URL/that/might/mess/up/your/theme/and/is/unsightly.php" class="autohyperlink">www.somelonghost.com</a>
  • With Hyperlink Mode set to 15
<a href="http://www.somelonghost.com/with/some/long/URL/that/might/mess/up/your/theme/and/is/unsightly.php" class="autohyperlink">www.somelonghos...</a>
  • With Hyperlink Mode set to 15, nofollow set to true, open in new window set to false, truncation before of "[", truncation after of "...]"
<a href="http://www.somelonghost.com/with/some/long/URL/that/might/mess/up/your/theme/and/is/unsightly.php" class="autohyperlink" rel="nofollow">[www.somelonghos...]</a>

Filters

The plugin exposes seven filters for hooking. Typically, customizations utilizing these hooks would be put into your active theme's functions.php file, or used by another plugin.

c2c_autohyperlink_urls_filters (filter)

This hook allows you to customize which filters get processed by the plugin.

Arguments:

  • $filters (array): The filters whose text should be auto-hyperlinked. Default array( 'the_content', 'the_excerpt', 'widget_text' ).

Example:

/**
 * Auto-hyperlink additional filters.
 *
 * @param array $filters
 * @return array
 */
function my_c2c_autohyperlink_urls_filters( $filters ) {
    // Add in another filter to process.
    $filters[] = 'my_custom_filter';
    return $filters;
}
add_filter( 'c2c_autohyperlink_urls_filters', 'my_c2c_autohyperlink_urls_filters' );

autohyperlink_urls_class (filter)

This hook allows you to customize the class added to links created by the plugin.

Arguments:

  • $class (string): The class name. Default 'autohyperlink'.

Example:

// Set default class for links added by Auto-hyperlink URLs.
add_filter( 'autohyperlink_urls_class', function ( $class ) { return 'myclass'; } );

autohyperlink_urls_link_attributes (filter)

This hook allows you to add custom attributes to links created by the plugin.

Arguments:

  • $attributes (array): The link attributes already created by the plugin.
  • $context (string): The context for the link. Either 'url' or 'email'. Default 'url'.
  • $title (string): The text for the link's title attribute.

Example:

/**
 * Output 'title' attribute for link, as done by plugin prior to v5.0.
 *
 * @param array  $attributes The attributes for the link tag.
 * @param string $context    The context for the link. Either 'url' or 'email'. Default 'url'.
 * @param string $title      The text for the link's title attribute.
 * @return array
 */
function add_title_attribute_for_autohyperlink_urls( $attributes, $context = 'url', $title = '' ) {
    if ( $title ) {
        $attributes['title'] = $title;
    }

    return $attributes;
}
add_filter( 'autohyperlink_urls_link_attributes', 'add_title_attribute_for_autohyperlink_urls' );

autohyperlink_urls_tlds (filter)

This hook allows you to custom the list of supported TLDs for non-URI scheme link auto-hyperlinking. Note that the value sent to the hook includes the default TLDs plus those added via the 'more_extensions' setting. Also note that the TLDs are defined as a '|'-separated string.

Arguments:

  • $tlds (string): The supported TLDs. Default 'com|org|net|gov|edu|mil|us|info|biz|ws|name|mobi|cc|tv'.

Example:

// Add support for more TLDs.
add_filter( 'autohyperlink_urls_tlds', function ( $tlds ) { return $tlds . '|in|io|tt'; } );

autohyperlink_urls_truncate_link (filter)

This hook allows you to custom how truncated links are displayed.

Arguments:

  • $url (string): The potentially truncated URL.
  • $original_url (string): The full, original URL.
  • $context (string): The context for the link. Either 'url' or 'email'. Default 'url'.

autohyperlink_urls_custom_exclusions (filter)

This hook allows you to define custom logic to determine if a link should be hyperlinked.

Arguments:

  • $should (bool): Should the link be hyperlinked? Default true.
  • $url (string): The full URL.
  • $domain (string): Just the domain/host part of the URL.

Example:

/**
 * Don't hyperlink links on the front page.
 *
 * @param  bool   $should
 * @param  string $url
 * @param  string $domain
 * @return bool
 */
function my_autohyperlink_urls_custom_exclusions( $should, $url, $domain ) {
    if ( is_front_page() ) {
        return false;
    } else {
        return $should;
    }
}
add_filter( 'autohyperlink_urls_custom_exclusions', 'my_autohyperlink_urls_custom_exclusions' );

autohyperlink_urls_exclude_domains (filter)

This hook allows you to specify domains that should not get auto-hyperlinked. Note that the value sent to the hook includes the value of the 'exclude_domains' setting. Note that only the domain (without URI scheme or trailing slash) should be specified.

Arguments:

  • $excluded_domains (array): The domains already being excluded. Default empty array.

Example:

/**
 * Exclude certain domains from being auto-hyperlinked.
 *
 * @param  array $excluded_domains
 * @return array
 */
function my_autohyperlink_urls_exclude_domains( $excluded_domains ) {
    $excluded_domains[] = 'youtube.com';
    $excluded_domains[] = 'example.com';
    return $excluded_domains;
}
add_filter( 'autohyperlink_urls_exclude_domains', 'my_autohyperlink_urls_exclude_domains' );

Requires: 4.1 or higher
Compatible up to: 4.5.3
Last Updated: 4 months ago
Active Installs: 8,000+

Ratings

4.8 out of 5 stars

Support

0 of 1 support threads in the last two months have been marked resolved.

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

100,1,1
100,1,1
100,1,1
50,2,1
100,5,5
100,1,1
100,1,1
100,2,2
100,1,1
100,1,1
100,2,2
100,1,1
100,1,1
100,2,2
100,1,1
100,1,1