• Hi all,

    Trying to add this Periscope script embed to my site as a menu item:

    <script>window.twttr=function(t,e,r){var n,i=t.getElementsByTagName(e)[0],w=window.twttr||{};return t.getElementById(r)?w:(n=t.createElement(e),n.id=r,n.src="https://platform.twitter.com/widgets.js",i.parentNode.insertBefore(n,i),w._e=[],w.ready=function(t){w._e.push(t)},w)}(document,"script","twitter-wjs")</script><a href="https://www.periscope.tv/twitterdev" class="periscope-on-air" data-size="small">@twitterdev</a>

    I’m not a whiz with jQuery/javascript. I’ve seen some articles on adding an OnClick event to a menu but in this case I just want the On Air button to show in main menu and reflect current status.

    Any ideas? Thanks in advance.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The script tag portion does not necessarily need to be adjacent to the anchor (link) tag portion, but I suppose it wouldn’t hurt if it’s all kept together. To insert this into the normal menu that’s defined in the WP back end and output by calling wp_nav_menu(), you can use the “wp_nav_menu_items” filter to add your own menu item, namely the Periscope script and link. I’m assuming this is the only menu displayed on your site, or you want it added to all menus. This filter will add an item to every menu used. A more specific filter is available if need be.

    You need to add another <li> item that matches your other menu items, using the new <li> item to wrap the added script and link. For example:

    add_filter('wp_nav_menu_items',
      function( $items ){
        $items .= '<li class="menu-item menu-item-type-custom menu-item-object-custom">';
        $items .= 'add your script and link here';
        return $items . '</li>';
    });
Viewing 1 replies (of 1 total)

The topic ‘Add Periscope Embed in Menu’ is closed to new replies.