WordPress.org

Plugin Directory

Linkify Text

Automatically hyperlink words or phrases in your posts.

Filters

The plugin exposes six filters for hooking. Typically, the code to utilize these hooks would go inside your active theme's functions.php file. Bear in mind that all of the features controlled by these filters are configurable via the plugin's settings page. These filters are likely only of interest to advanced users able to code.

c2c_linkify_text_filters (filter)

The 'c2c_linkify_text_filters' hook allows you to customize what hooks get text linkification applied to them.

Arguments:

  • $hooks (array): Array of hooks that will be text linkified.

Example:

/**
 * Enables text linkification for custom fields.
 *
 * @param array $filters The filters handled by the Linkify Text plugin.
 */
function more_text_replacements( $filters ) {
    $filters[] = 'the_meta'; // Here you could put in the name of any filter you want
    return $filters;
}
add_filter( 'c2c_linkify_text_filters', 'more_text_replacements' );

c2c_linkify_text_comments (filter)

The 'c2c_linkify_text_comments' hook allows you to customize or override the setting indicating if text linkification should be enabled in comments.

Arguments:

  • $state (bool): Either true or false indicating if text linkification is enabled for comments. The default value will be the value set via the plugin's settings page.

Example:

// Prevent text linkification from ever being enabled in comments.
add_filter( 'c2c_linkify_text_comments', '__return_false' );

c2c_linkify_text (filter)

The 'c2c_linkify_text' hook allows you to customize or override the setting defining all of the text phrases and their associated links.

Arguments:

  • $linkify_text_array (array): Array of text and their associated links. The default value will be the value set via the plugin's settings page.

Example:

/**
 * Programmatically adds more text to be linked.
 *
 * @param array $text_to_links Array of text and their associated URLs.
 */
function my_text_linkifications( $text_to_links ) {
    // Add text link
    $text_to_links['Matt Mullenweg'] => 'https://ma.tt';

    // Unset a text link that we never want defined
    if ( isset( $text_to_links['WordPress'] ) ) {
        unset( $text_to_links['WordPress'] );
    }

    // Important! Return the changes.
    return $text_to_links;
}
add_filter( 'c2c_linkify_text', 'my_text_linkifications' );

c2c_linkify_text_case_sensitive (filter)

The 'c2c_linkify_text_case_sensitive' hook allows you to customize or override the setting indicating if text matching for potential text linkification should be case sensitive or not.

Arguments:

  • $state (bool): Either true or false indicating if text matching is case sensitive. The default value will be the value set via the plugin's settings page.

Example:

// Prevent text matching from ever being case sensitive.
add_filter( 'c2c_linkify_text_case_sensitive', '__return_false' );

c2c_linkify_text_replace_once (filter)

The 'c2c_linkify_text_replace_once' hook allows you to customize or override the setting indicating if text linkification should be limited to once per term per piece of text being processed regardless of how many times the term appears.

Arguments:

  • $state (bool): Either true or false indicating if text linkification is to only occur once per term. The default value will be the value set via the plugin's settings page.

Example:

// Only linkify a term once per post.
add_filter( 'c2c_linkify_text_replace_once', '__return_true' );

c2c_linkify_text_linked_text (filter)

The 'c2c_linkify_text_linked_text' hook allows you to customize or override the replacement link markup for a given string.

Arguments:

  • $new_text (string): The link markup that will replace $old_text.
  • $old_text (string): The text being replaced/linkified.
  • $link (string): The URL that $old_text is to be linked to.
  • $text_to_link (array): The full array of text and the URLs they should link to.

Example:

See the "Can I change how the link gets created because I want to add a 'title' attribute to the link?" in the FAQ.

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

Ratings

3.4 out of 5 stars

Support

Got something to say? Need help?

Compatibility

+
=
Not enough data

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

100,1,1
0,1,0
100,1,1