WordPress.org

Ready to get started?Download WordPress

Forums

Injecting a javascript banner code right before & after wordpress navigation men (2 posts)

  1. z0haib
    Member
    Posted 3 months ago #

    I am trying to develop a plugin to inject a javascript banner code right before and after the wordpress navigation menu but I am unable to find any solution to this problem. Does anyone have any idea?

    I cannot append to a Div ID either since every wordpress theme uses different div id and class for navigation menu.

    Thanks

  2. bcworkz
    Member
    Posted 3 months ago #

    It's difficult to inject content from a plugin precisely because themes use different ways to display content, not just IDs and classes. For any theme that uses wp_nav_menu() to display navigation, use the 'wp_nav_menu' filter to place your own empty divs before and after the nav HTML. You can then use javascript to fill the divs with whatever. I would hope nearly all themes use this function, but there are no doubt a few mavericks that do not. Unless you want to develop custom code for each of these, they are pretty much a lost cause.

Reply

You must log in to post.

About this Topic

Tags