Skip to main content
100%

Gist 95caa5a3cc0b546ba00efcf8ed574a3d

✓ Published0🌍 Public
KKopylovVitalik
Last edited Nov 18, 2020
Created on Nov 18, 2020

This example demonstrates a WordPress navigation menu filter that removes cyclical links by replacing anchor tags with non-link spans. The code hooks into the `wp_nav_menu` filter and applies a PHP regular expression via `preg_replace` to match `<a>` elements containing `aria-current="page"` and convert them to `<span>` elements with the same attribute. This prevents the current page from being rendered as a clickable link, effectively eliminating self-referencing navigation entries. The implementation relies on WordPress's `add_filter` API and requires PHP's regex engine to identify and transform the markup.

AI-generated description

Similar vizzes