A WordPress plugin that adds dynamic anchor management to menu items with automatic URL updates when page slugs change.
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.
- 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
- Elementor integration for adding anchors to Elementor elements
- Protection against path traversal and query parameter injection
- XSS prevention through proper output escaping
- Safe character filtering for URL anchors
- Input validation and sanitization
- Multi-language support out of the box
- Available in: English (default), French, Spanish
- Translation-ready with complete
.pot
template - RTL languages supported
- Domain-driven architecture with clean separation of concerns
- WordPress coding standards compliant
- Extensible design with proper hooks
- Helper functions for developers
- Comprehensive documentation
- Go to Plugins > Add New
- Search for "Anchor Dynamic URL"
- Install and activate the plugin
- Download the plugin zip file
- Upload to
/wp-content/plugins/anchor-dynamic-url/
- Activate through the WordPress plugins screen
# 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
- 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
- Edit an Elementor page
- Select any element that supports URL (e.g., buttons, links, titles, etc.)
- In the element settings, find the "URL" field
- Click to "⚙️" to open URL options
- Enter your anchor in the "Target Anchor" field (e.g.,
contact-section
) - Save the element
- The anchor will be applied to the element.
The plugin supports various naming conventions:
- camelCase:
contactSection
- PascalCase:
ContactSection
- kebab-case:
contact-section
- snake_case:
contact_section
Input is automatically sanitized:
"Contact Section"
→"Contact-Section"
"section?param=1"
→"section"
"test/path"
→"test"
"anchor\\injection"
→"anchor"
// Get anchor for a specific menu item
$anchor = get_menu_item_anchor($menu_item_id);
if ($anchor) {
echo "Anchor: " . $anchor;
}
The plugin follows domain-driven design principles:
┌─────────────────────┐
│ AnchorDynamicUrlManager │ ← Main orchestrator
└─────────┬───────────┘
│
┌─────────▼───────────┐
│ AnchorService │ ← Business logic
└─────────┬───────────┘
│
┌─────────▼───────────┐
│ AnchorRepository │ ← Data persistence
└─────────┬───────────┘
│
┌─────────▼───────────┐
│ MenuItemAnchor │ ← Domain entity
└─────────────────────┘
AnchorItem
- Domain entity containing business rulesAnchorRepository
- Data access layer using WordPress meta APIAnchorService
- Application logic and UI managementAnchorDynamicUrlManager
- Main controller and WordPress integration
- WordPress: 5.0 or higher
- PHP: 7.4 or higher
- Database: Uses WordPress native meta system (no additional tables)
- ✅ WordPress: 5.0 - 6.4+ (tested)
- ✅ PHP: 7.4 - 8.3
- ✅ Multisite: Single-site installations only
- ✅ Themes: Compatible with all themes
- ✅ Page Builders: Elementor, Gutenberg, etc.
- ✅ Caching: Compatible with all major caching plugins
# 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
- Follows WordPress Coding Standards
- PSR-4 autoloading compatible
- Object-oriented architecture
- Comprehensive inline documentation
- 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
// 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);
// 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);
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
See CHANGELOG.md for detailed version history.
A: Existing menu items continue to work normally. The anchor field is optional and only affects items where you add anchors.
A: No. Menu items will revert to their original URLs. No data is lost.
A: For security and compatibility, only letters, numbers, hyphens, and underscores are allowed. Other characters are automatically removed.
A: Yes, the plugin works with any post type that can be added to WordPress menus.
A: Yes, the plugin is fully translatable and works with WPML, Polylang, and other translation plugins.
- 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
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.
Developed with ❤️ by Hylbee
Built using domain-driven design principles and modern WordPress development practices.