# Mark the Current Page in Menus Built With Blocks and Widgets

> Adds aria-current="page" to any link on the page that points to the page being viewed, for menus, widget link lists and footer links that do not mark it themselves.

- Type: HTML
- Runs: Site-wide footer
- Category: [Accessibility](https://wpide.com/library/category/accessibility/)
- Tags: navigation, aria, links
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/a11y-aria-current-links/

## Code

```html
<script>
(function () {
    var here = location.origin + location.pathname.replace(/\/$/, '');
    document.querySelectorAll('nav a[href], .widget a[href], footer a[href]').forEach(function (a) {
        if (a.hasAttribute('aria-current') || !a.href) { return; }
        var url;
        try { url = new URL(a.href); } catch (e) { return; }
        if (url.hash && url.pathname === location.pathname) { return; }
        if (url.origin + url.pathname.replace(/\/$/, '') === here) { a.setAttribute('aria-current', 'page'); }
    });
})();
</script>
```

## Notes

Links that already carry aria-current are not changed.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Mark the Current Page in Menus Built With Blocks and Widgets" in its snippet library and add it in one click; or create a new HTML snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
