Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/jdyach/external-link-tagger/archive/refs/heads/main.zipA WordPress plugin that automatically adds target="_blank" and rel="noopener noreferrer" to external links in post content, excerpts, and text widgets — with a simple settings page to control where it applies.
Features
- Processes links in post content, excerpts, and text widgets (each toggleable)
- Uses DOMDocument for reliable HTML parsing — no fragile regex
- Detects external links by comparing the link hostname against
home_url(), so subdomains of your own site are never tagged - Skips non-HTTP links (
mailto:,tel:,#anchors,javascript:) automatically - Preserves any existing
relattribute values — only appends what's missing - Settings page under Settings → External Link Tagger
- Defaults all options to on at activation via
register_activation_hook
Installation
- Upload the
external-link-taggerfolder to/wp-content/plugins/ - Activate through Plugins → Installed Plugins
- Optionally adjust which areas are tagged under Settings → External Link Tagger
How It Works
The plugin hooks into the_content, the_excerpt, and widget_text filters. Each filter runs the HTML through DOMDocument::loadHTML(), iterates all <a> tags, checks whether the href is external, and sets target and rel attributes. The modified HTML is returned from saveHTML().
Settings are stored as a single serialized array in wp_options via the WordPress Settings API.
WordPress Concepts Demonstrated
| Concept | Where Used |
|---|---|
Content filters (the_content, the_excerpt, widget_text) |
class-elt-tagger.php |
DOMDocument HTML parsing |
class-elt-tagger.php |
home_url() + wp_parse_url() for host comparison |
class-elt-tagger.php |
Settings API (register_setting, add_settings_section/field) |
class-elt-settings.php |
register_activation_hook for default options |
external-link-tagger.php |
add_options_page |
class-elt-settings.php |
wp_parse_args for option defaults |
class-elt-tagger.php |
File Structure
external-link-tagger/
├── external-link-tagger.php # Bootstrap, constants, activation hook
├── README.md
├── assets/
│ └── css/
│ └── admin.css # Settings page styles
└── includes/
├── class-elt-tagger.php # Core DOMDocument link processing
└── class-elt-settings.php # Settings API page
Requirements
- WordPress 6.0+
- PHP 8.0+
License
GPL-2.0-or-later