Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7086049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:30:04+00:00 2026-05-28T07:30:04+00:00

Does anyone have a working example of a WordPress menu outputted manually? The one

  • 0

Does anyone have a working example of a WordPress menu outputted manually? The one on the Codex didn’t seem to work, though my menu_name slug of “Footer” can’t be that complicated..? I need to add offscreen spans within external menu links for accessibility purposes. I already have CSS classes; what I need is specific markup added via the functions.php file.

The basic code I’m looking for (see list items w/ ‘external’ class. Hrefs changed to # for code brevity, they link offsite in real life):

<ul id="menu-footer" class="menu">
    <li class="menu-item">
        <a href="#">About Us</a>
    </li>
    <li class="external menu-item">
        <a title="Link opens in a new window." target="_blank" href="#">Terms &amp; Conditions <span class="offscreen">Opens in a new window</span></a>
    </li>
    <li class="menu-item">
        <a href="#">Comments Policy</a>
    </li>
    <li class="external menu-item">
        <a title="Link opens in a new window." target="_blank" href="#">Privacy Statement<span class="offscreen">Opens in a new window</span></a>
    </li>
    <li class="menu-item">
        <a href="#">Contact Us</a>
    </li>
</ul>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:30:05+00:00Added an answer on May 28, 2026 at 7:30 am

    Answer: the nav menu has to be registered & assigned to the theme for the Codex example to work. DUH!

    in functions.php:

    // default register any navigation menus
    register_nav_menus(
        array(
          'footer' => 'Footer Menu',
          'links' => 'Links Menu'
        )
    );
    

    Assign menu(s) to your theme:

    assign a menu to your theme

    Back in functions.php:

    function accessibleAnchors($menu_name, $link_after = NULL){
        if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $menu_name ] ) ) {
            $menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
    
            $menu_items = wp_get_nav_menu_items($menu->term_id);
    
            $menu_list = '<ul id="menu-' . $menu_name . '" class="menu">';
    
            foreach ( (array) $menu_items as $key => $menu_item ) {
                // uncomment next line to see all array values
                // print_r($menu_item);
                $linkText = $menu_item->title;
                $url = $menu_item->url;
                $target = $menu_item->target;
                $titleAttr = $menu_item->attr_title;
                // hard-coding the first & only CSS class here, you could loop through others
                $cssClass = $menu_item->classes[0];
    
                if($target == '_blank'):
                   $titleAttr = " title=\"$titleAttr\"";
                   $span = "<span class=\"offscreen\"> Opens in a new window</span>";
                else:
                   $span = "";
                endif;
    
                $menu_list .= '<li class="menu-item '.$cssClass.'"><a href="' . $url . '"'.$titleAttr. '>' . $linkText . $span . $link_after .'</a></li>';
            }
            $menu_list .= '</ul>';
        }
        return $menu_list;
    }
    

    Now call the function in your template:

    <?php echo accessibleAnchors('footer'); ?>
    

    Boom.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have a working example of a video player built using Qt phonon?
ref: Dynamic Control ID Does anyone have a working example of creating the ID
Does anyone have a working example of importing a local file as a module
Does anyone have a working example of using the new GWT constructs for RequestFactory
Does anyone out there have a working example of the Facebook live stream plugin
does anyone have a generic working example of the use of the ExpertR9.dll library
Does anyone have a working class or function to create the hashed email that
Does anyone have any useful advice/links to information about working with mp3 files in
Does anyone have any experience with doing this? I'm working on a Java decompiler
Does anyone know of a working fix for the ie z-index bug? I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.