Set active state on navigation dynamically

前端 未结 6 1256
遇见更好的自我
遇见更好的自我 2021-01-05 20:33

I seem to run into this problem frequently and can never find a solution. I have a Wordpress site with a top navigation. Since this is in my header.php, and used on all page

6条回答
  •  清歌不尽
    2021-01-05 21:07

    First, there is a css pseudo class prepared for styling 'active' links :

    a:active {css}
    

    For your situation, you would have to add this class to your styling :

    .active a, a:active {css}
    

    But your needs seems more on the PHP side than the CSS, perhaps someone else will help you with that part. There would be a javascript solution with jQuery, finding the actual location then inject a css selector to the proper element.

    Check this article and this other one about wordpress. It will help you.

    Stack Overflow references :

    • How do I target each menu different items on active state in Wordpress
    • How to add Active states and icons in wordpress wp_nav_menu()
    • Loosing Nav Active State in Wordpress Dynamic Menu
    • google search

提交回复
热议问题