# Auto-Linking

> **TL;DR:** You define keywords and Link Manager Pro automatically converts them into links throughout your content. You set priority, case sensitivity, a maximum number of replacements per page and per keyword, and choose whether to skip headings. A tiered caching system prevents performance impact.

Automatically convert keywords into links throughout your content — for both affiliate partners and individual links.

## What Is Auto-Linking?

Auto-linking scans your post content for specific keywords and replaces them with links. You define the keywords once, and the plugin handles every future occurrence across your configured post types.

Both **affiliates** and **individual links** support auto-linking. Each has its own keywords, priority, and enable toggle.

## How It Works

1. You enable auto-linking and define keywords on an affiliate or an individual link.
2. When WordPress renders a post, the plugin's `the_content` filter (priority 99) processes the content.
3. The plugin builds a keyword map from all affiliates and links that have auto-linking enabled.
4. Keywords are matched in the post content and replaced with the corresponding links.

### Where Auto-Linking Runs

Auto-linking runs on the `the_content` WordPress filter. It **skips** these contexts:

- Admin pages
- AJAX requests
- Cron jobs
- REST API requests

It only processes the post types you configure in the **autolink_post_types** setting.

## Settings

Go to **Link Manager Pro → Settings → Auto-Linking** to configure:

| Setting | Description |
|---------|-------------|
| **autolink_enabled** | Master toggle — turns auto-linking on or off |
| **autolink_case_sensitive** | Match exact letter case only |
| **autolink_exclude_headings** | Skip `h1`–`h6` heading tags during replacement |
| **autolink_max_per_keyword** | Maximum replacements per keyword per page |
| **autolink_max_per_page** | Maximum total auto-links inserted per page |
| **autolink_post_types** | Which post types to process (e.g., post, page) |

## Setting Up Affiliate Auto-Linking

1. Go to **Link Manager Pro → Affiliate Partners**.
2. Create or edit a partner.
3. Enable **Auto-Link** for this affiliate.
4. Add **Keywords** (one per line or comma-separated):

```
WordPress hosting
recommended host
best web host
```

5. Set the **Priority** (lower numbers match first, default: 10).
6. Click **Register Partner** or **Update Partner**.

Every occurrence of those keywords in your content becomes a link to that affiliate's masked URL.

## Setting Up Link Auto-Linking

Individual links also support auto-linking, independent of affiliates:

1. Go to **Link Manager Pro → Pretty Links**.
2. Create or edit a link.
3. Enable **Auto-Link** for this link.
4. Add **Keywords** (one per line or comma-separated).
5. Set the **Priority** (lower numbers match first, default: 10).
6. Save the link.

This is useful for linking product names, tools, or internal resources without creating an affiliate partner.

## Keyword Map Building

When the auto-link filter runs, the plugin builds a keyword map using this process:

1. Collects all affiliates with auto-linking enabled and all individual links with auto-linking enabled.
2. Sorts entries by: **tier** (affiliate vs. link) → **priority** (lower first) → **ID** → **keyword length** (longer first).
3. Deduplicates — the first match wins when two sources define the same keyword.
4. Enforces a maximum of **200 keywords** total.
5. Compiles a single regex alternation pattern for a one-pass replacement across the content.

### Priority and Conflicts

If an affiliate and an individual link both define the keyword "Shopify," the entry with the lower priority number wins. If priorities are equal, the affiliate takes precedence (sorted by tier). If both are the same tier and priority, the lower ID wins.

Longer keywords match before shorter ones within the same priority level, which prevents partial matches from consuming a longer keyword.

## Caching

The keyword map is cached in two layers:

| Layer | Storage | TTL |
|-------|---------|-----|
| **L1** | `wp_cache` (in-memory) | Until the request ends |
| **L2** | WordPress transient (database) | 3,600 seconds (1 hour) |

The cache is automatically invalidated when you create, update, or delete any link or affiliate.

## Keyword Best Practices

### Good Keywords

- Specific phrases: "WordPress hosting", "email marketing software"
- Brand names: "Shopify", "ConvertKit"
- Product names: "iPhone 15", "Samsung Galaxy S24"

### Bad Keywords

- Too generic: "hosting", "software", "best"
- Too short: "web", "tool", "app"
- Common words: "click", "here", "link"

### Tips

- Use 2–4 word phrases for specificity.
- Enable **case-sensitive matching** when keywords overlap with common words.
- Set `autolink_max_per_keyword` to 1–3 to avoid over-linking a single post.
- Set `autolink_max_per_page` to keep total link density reasonable.
- Test keywords on existing content to verify the results.

## Use Cases

### Affiliate Marketing

Automatically link product mentions to affiliate links:

- Keywords: "Blue Yeti microphone", "Shopify platform"
- Every matching mention becomes an affiliate link

### Internal Linking

Boost SEO with automatic internal links:

- Add keywords like "pricing page" or "documentation" to individual links
- The plugin links every occurrence to the correct internal page

### Brand Partnerships

Maintain consistent partner links across all content:

- Add partner brand names as keywords on their affiliate profile
- All mentions link to the correct partner URL

### Resource Pages

Link to recommended tools and resources:

- Keywords: "WordPress theme", "hosting provider"
- Consistent links across all content without manual editing

---

**Step-by-step guide:** [How to Manage Affiliate Links in WordPress](https://docs.linkmanagerpro.com/guides/manage-affiliate-links)
