Halloween Sale 15% off Ends in See the plans
Universal

Skip Links to Navigation, Search and Footer

Adds a small set of keyboard skip links (main content, main menu, search and footer) that appear on the first Tab press. Links whose target is missing on a page are removed automatically.

Don’t have WPIDE yet? Install it on your site

Code

<nav class="wpide-skiplinks" aria-label="<?php echo esc_attr__( 'Skip links' ); ?>">
    <a href="#" data-target="main, #main, .site-main, #content">Skip to main content</a>
    <a href="#" data-target="#site-navigation, nav.main-navigation, header nav, .wp-block-navigation">Skip to main menu</a>
    <a href="#" data-target="form[role=search] input[type=search], .search-field, .wp-block-search__input">Skip to search</a>
    <a href="#" data-target="footer, #colophon, .site-footer">Skip to footer</a>
</nav>
<style>
.wpide-skiplinks a{position:absolute;left:-9999px;top:8px;z-index:100002;padding:10px 16px;background:#111;color:#fff;font-size:16px;text-decoration:underline;border-radius:4px;}
.wpide-skiplinks a:focus{left:8px;outline:3px solid #fff;outline-offset:-6px;}
</style>
<script>
(function () {
    document.querySelectorAll('.wpide-skiplinks a').forEach(function (link, i) {
        var target = document.querySelector(link.getAttribute('data-target'));
        if (!target) { link.remove(); return; }
        if (!target.id) { target.id = 'wpide-skip-target-' + i; }
        if (!/^(A|BUTTON|INPUT|SELECT|TEXTAREA)$/.test(target.tagName) && !target.hasAttribute('tabindex')) {
            target.setAttribute('tabindex', '-1');
        }
        link.setAttribute('href', '#' + target.id);
        link.addEventListener('click', function () { setTimeout(function () { target.focus(); }, 0); });
    });
})();
</script>

Notes

Adjust the CSS selectors in the data-target attributes to match your theme's header, menu, search and footer.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.