WordPress.org

Ready to get started?Download WordPress

Forums

WordPress add class to parent element if has submenu (3 posts)

  1. iversoncreative
    Member
    Posted 1 year ago #

    I need to be able to add classes to a parent <li> as well as the child <ul> element in WordPress like so:

    <ul>
        <li>Top Level Page</li>
        <li class="NEED-NEW-CLASS-HERE">Top Level Page with Children
            <ul class="AND-HERE">
                <li>Child Page</li>
            </ul>
        </li>
    </ul>

    I can't quite seem to grasp the whole walker thing, and do not want to do it via jquery. This seems common enough, but I can't find a working answer anywhere. Has anyone here seen or done this? Any help and insight would be greatly appreciated.

  2. thisislawatts
    Member
    Posted 1 year ago #

    As this page was pretty quickly returned in my Google search, fellow knowledge seekers can find a solution over on StackOverflow --> http://stackoverflow.com/questions/8448978/wordpress-how-do-i-know-if-a-menu-item-has-children

  3. mread1208
    Member
    Posted 1 year ago #

    That worked like a charm, thanks for the post.

Topic Closed

This topic has been closed to new replies.

About this Topic