Install
Upload it under Plugins → Add New Plugin → Upload Plugin, then activate.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/hylbee/anchor-dynamic-url/releases/download/v1.5.1/anchor-dynamic-url_1.5.1.zipA WordPress plugin that adds dynamic anchor management to menu items with automatic URL updates when page slugs change.
Description
Anchor Dynamic URL solves a common WordPress problem: broken anchor links when page slugs change. Instead of manually writing URLs like https://example.com/contact#coordinates, you simply select a page and add an anchor. The plugin automatically generates the correct URL and updates it if the page slug changes.
Features
✨ Core Features
- Dynamic anchor management for WordPress menu items
- Automatic URL updates when page slugs change
- GitHub-based update system with automatic notifications
- Security-first approach with input sanitization
- Case-sensitive anchors preserved as entered
- Clean, intuitive interface integrated into WordPress menus
- Full Elementor integration: widgets, sections, columns, and linked containers
🛡️ Security
- Protection against path traversal and query parameter injection
- XSS prevention through proper output escaping
- Safe character filtering for URL anchors (
a-zA-Z0-9-_only) - Input validation and sanitization on all user inputs
- Nonce verification + capability check (
edit_theme_options) on menu saves preg_replace_callbackused throughout to prevent regex backreference injection
🌍 Internationalization
- Multi-language support out of the box
- Available in: English (default), French, Spanish
- Translation-ready with complete
.pottemplate - RTL languages supported
🏗️ Developer-Friendly
- Domain-driven architecture with clean separation of concerns
- WordPress coding standards compliant
- Extensible design with proper hooks
- Helper functions for developers
- Comprehensive documentation
Installation
From WordPress Admin
- Go to Plugins > Add New
- Search for "Anchor Dynamic URL"
- Install and activate the plugin
Manual Installation
- Download the plugin zip file
- Upload to
/wp-content/plugins/anchor-dynamic-url/ - Activate through the WordPress plugins screen
From Source
# Clone the repository
git clone https://github.com/Hylbee/anchor-dynamic-url.git
# Copy to WordPress plugins directory
cp -r anchor-dynamic-url /path/to/wordpress/wp-content/plugins/
# Generate translation files (optional)
cd anchor-dynamic-url/languages
msgfmt anchor-dynamic-url-fr_FR.po -o anchor-dynamic-url-fr_FR.mo
Usage
Basic Usage
- Go to Appearance > Menus in WordPress admin
- Edit or create a menu item
- In the menu item details, you'll see a new "Anchor (optional)" field
- Enter your anchor (e.g.,
contact-section) - Save the menu
The plugin will automatically generate the URL: https://yoursite.com/page#contact-section
Elementor Integration
Widgets, sections & columns
- Edit an Elementor page
- Select any element that has a URL control (button, heading, icon, etc.)
- Open the URL field settings
- Enter your anchor in the "Target Anchor" field (e.g.,
contact-section) - Save — the
#anchoris appended to the URL at render time
Containers with link wrapping
- Select a Container element
- Set HTML Tag to
aand enter a URL in the link field - Enter the anchor in the "Target Anchor" field
- The container's
hrefis rewritten via output buffering at render time
Advanced Usage
Anchor Naming Conventions
The plugin supports various naming conventions:
- camelCase:
contactSection - PascalCase:
ContactSection - kebab-case:
contact-section - snake_case:
contact_section
Security Features
Input is automatically sanitized:
"Contact Section"→"Contact-Section""section?param=1"→"section""test/path"→"test""anchor\\injection"→"anchor"
Developer Helper
// Get anchor for a specific menu item
$anchor = get_menu_item_anchor($menu_item_id);
if ($anchor) {
echo "Anchor: " . $anchor;
}
Architecture
The plugin follows domain-driven design principles:
┌─────────────────────┐
│ AnchorDynamicUrlManager │ ← Main orchestrator
└─────────┬───────────┘
│
┌─────────▼───────────┐
│ AnchorService │ ← Business logic
└─────────┬───────────┘
│
┌─────────▼───────────┐
│ AnchorRepository │ ← Data persistence
└─────────┬───────────┘
│
┌─────────▼───────────┐
│ MenuItemAnchor │ ← Domain entity
└─────────────────────┘
Component Responsibilities
AnchorItem- Domain entity containing business rulesAnchorRepository- Data access layer using WordPress meta APIAnchorService- Application logic and UI managementAnchorDynamicUrlManager- Main controller and WordPress integration
Requirements
- WordPress: 5.0 or higher
- PHP: 7.4 or higher
- Database: Uses WordPress native meta system (no additional tables)
Compatibility
- ✅ WordPress: 5.0 - 7.0 (tested, including 7.0 prerelease)
- ✅ PHP: 7.4 - 8.3
- ✅ Multisite: Single-site installations only
- ✅ Themes: Compatible with all themes
- ✅ Elementor: 3.5+ (uses
unregister/registerAPI) - ✅ Caching: Compatible with all major caching plugins
Development
Local Development Setup
# Clone repository
git clone https://github.com/Hylbee/anchor-dynamic-url.git
# Create symbolic link in WordPress
ln -s /path/to/anchor-dynamic-url /path/to/wordpress/wp-content/plugins/
# Install development dependencies (if any)
composer install --dev
Code Standards
- Follows WordPress Coding Standards
- PSR-4 autoloading compatible
- Object-oriented architecture
- Comprehensive inline documentation
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
API Reference
Hooks
Actions
// Before anchor field is displayed
do_action('menu_anchor_before_field', $item_id, $item, $depth, $args);
// After anchor is saved
do_action('menu_anchor_saved', $menu_item_id, $anchor_value);
Filters
// Modify anchor before saving
$anchor = apply_filters('menu_anchor_sanitize', $anchor, $menu_item_id);
// Modify final URL
$url = apply_filters('menu_anchor_url', $url, $menu_item_id, $anchor);
Functions
get_menu_item_anchor($menu_item_id)
Returns the anchor for a specific menu item.
Parameters:
$menu_item_id(int) - Menu item ID
Returns:
- (string|null) - Anchor value or null if not set
Changelog
See CHANGELOG.md for detailed version history.
Frequently Asked Questions
Q: What happens to existing menu items?
A: Existing menu items continue to work normally. The anchor field is optional and only affects items where you add anchors.
Q: Will this break my menu if I deactivate the plugin?
A: No. Menu items will revert to their original URLs. No data is lost.
Q: Can I use special characters in anchors?
A: For security and compatibility, only letters, numbers, hyphens, and underscores are allowed. Other characters are automatically removed.
Q: Does this work with custom post types?
A: Yes, the plugin works with any post type that can be added to WordPress menus.
Q: Is this compatible with multilingual sites?
A: Yes, the plugin is fully translatable and works with WPML, Polylang, and other translation plugins.
Support
- Documentation: https://github.com/Hylbee/anchor-dynamic-url/blob/main/README.md
- Support Forum: https://github.com/Hylbee/anchor-dynamic-url/issues
- Issues: GitHub Issues
License
This plugin is licensed under the GPL v2 or later.
Anchor with dynamic URL - WordPress Plugin
Copyright (C) 2025 Hylbee
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Credits
Developed with ❤️ by Hylbee
Built using domain-driven design principles and modern WordPress development practices.
Releases
11 releases. Each count is every asset in that release; expand a row for the breakdown.