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

  • Home
  • SEARCH
  • 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 1033191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:11:41+00:00 2026-05-16T14:11:41+00:00

is it possible to add some kind of class like ‘arrow’ or a span

  • 0

is it possible to add some kind of class like ‘arrow’ or a span inside the menus that have submenus (in WordPress)?
it seems that you can do this is using javascript, but I want to know if there’s a PHP solution…

in WP 3.0, I saw that active menus have the “parent” or “ancestor” classes on them, but this is only for active menu, and I need it for inactive ones as well

  • 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-16T14:11:42+00:00Added an answer on May 16, 2026 at 2:11 pm

    This functionality really should be in WordPress core!
    Anyway, I had a look at the menu template source you sent in a comment on the other answer, and have found a (rather hacky) way to add a class on menu items with children. It basically subclasses the default walker to extend its default behaviour. It’s probably best if you put it in your theme’s functions.php. Here’s the code:

    <?php
    class Arrow_Walker_Nav_Menu extends Walker_Nav_Menu {
        function display_element($element, &$children_elements, $max_depth, $depth=0, $args, &$output) {
            $id_field = $this->db_fields['id'];
            if (!empty($children_elements[$element->$id_field])) { 
                $element->classes[] = 'arrow'; //enter any classname you like here!
            }
            Walker_Nav_Menu::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
        }
    }
    ?>
    

    To call it, you’ll need to add the walker argument when you call wp_nav_menu() in your theme, like so:

    <?php 
    wp_nav_menu(array('walker' => new Arrow_Walker_Nav_Menu, [other arguments...]))
    ?>
    

    Hope that works for you! I’ve only tested it superficially, but it seems to work. Let me know if there are any edge cases where adding the class fails.

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

Sidebar

Related Questions

Is it possible to add some kind of restriction to the web.config to limit
Is it possible to add some kind of properties to a Wordpress page? In
Is it possible to add icons to all/some of the menu-links in your account-dashboard?
I used glade to create some gtk buttons. is it possible to add an
Is it possible to add to PHP objects on the fly? Say I have
I have some beans for which, in specific injections, I want to add a
I have a class that is serializing very nicely - finally! Now I want
I was just wondering if this is possible. I have a site that admins
I've got a function inside a class (A) that essentially takes as a parameter
I have a module that performs some calculations and during the calculations, communicates with

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.