Below is the script of the video. If youíre having a hard time digesting
what Iím saying, the script below might help!
Hi, in this tutorial we will try to add a login and logout entry on the main navigation of our website. So weíre gonna open our demo site. Now we got the Home and then the Contact Us as the main navigation. What we want to do is to add a Login or Logout button next to the navigation. The first thing that we need to do is head over on our dashboard and go to menus itself. Looks like we got the home and then the contact us. The important factor that weíre looking for, is the name of the navigation itself and the theme location.
Easily add Login – Logout Button
Shown in the video is that little piece of snippets. We’re going to copy the†codes right there, then go on the editor. Iím just gonna open this in a new tab. Depending on your theme, really doesnít matter what theme it is, all you need to do is look for the functions .php. The filename itself is functions.php. Iím gonna edit that. What we need to do is scroll down the very bottom.† And then weíre gonna hit a couple of enter keys and paste in the code. Just for the sake of†commenting out, Iím just gonna add a comment which says add login logout in the menu.†Then weíre just gonna hit†update. Then Iím gonna reload the site and you can see the logout button that†means Iím already login.
Letís try opening the same url on a Firefox. Just copy and paste the url and as you can see the term there is login because Iím not login. And on the first one you can see the term logout, because Iím already login. If Iím gonna click login it will automatically go in the login page. But when I click logout it should automatically log me out.
Let me just explain a little bit on our piece of code. (See video for the actual demo.) What it says is, we got a filter right there which is wp nav menus, then we got the items and the arguments. Now it says, when the argument theme location is equal to top. So that is the most important one, because that thing varies from theme to theme. Now we got that little thing right there which is the dumping the value of the arguments.Now letís try to do that,. What Iím gonna do is head back on the functions.php. Weíre gonna delete // right there and then hit update. Now if Iím gonna reload, it will display all the value of the arguments.
As you can see there, we got the theme location equal to top. If youíre using a different theme, then the value might differ. Now if there is no value using the theme location, then you might as well try different one something like menu_id right there. These are all unique from menu to menu right there. You cannot use the menu_class as an argument because all the menus might just display the menu as a class.
Changing Target Entity
We might as well use the menu_id, so If weíre gonna use it, just copy the menu_id. Letís say your theme doesnít have the argument theme location. So weíre gonna use the theme id. Copy that and then go back to your little piece of code,. Then change theme location to theme id. The value of the theme id is top-menu.†I’m gonna copy that and paste it on our piece of code. Iím gonna copy the entire code, and then head back on our functions.php.†Delete the code right there, replace it with the new entire code that we†just edited. And with the new argument which is the menu_id.
Okay, so if I’m gonna reload again, the logout button should stay right there. Weíre able to utilize another way of implementing the insertion of the menu item. That little piece of code is your gateway to properly inserting menu items!†
Okay I hope that helps and if you got any questions let me know in the comment below. Thanks!