Add facebook like button on the menu - last item

The function will be added in wp-content/themes/kleo-child/functions.php

COPY CODE

add_filter( 'wp_nav_menu_items', 'kleo_add_menu_item_like', 220, 2 );
function kleo_add_menu_item_like ( $items, $args )
{
    ob_start();
    ?>
    <div id="fb-root"></div>
    <script>(function(d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.6&appId=595976700546435";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));</script>


    <div class="fb-like" data-href="https://developers.facebook.com/docs/plugins/" data-layout="button" data-action="like" data-show-faces="false" data-share="false">

    </div>

    <?php

    $like = ob_get_clean();

    if ($args->theme_location == 'primary')
    {
        $items .= '<li id="nav-menu-item-like" class="menu-item">' . $like . '</li>';
    }
    return $items;
}

Log in with your credentials

Forgot your details?