Almost nothing is more frustrating for a user than searching around for a login link in order to get to important content.
The following method found at Vandweerd.com will automatically detect whether a user is logged in or not and put a login or a logout link right on your menu bar.
*** Please note, this method only works when you are using WordPress’ custom menus. (The menu function available in the admin section: Appearance > Menus.)
Add Code to Your Functions File
You will need to add a bit of code to your functions file for this. But after copying and pasting this code, you’re finished.
Go to Appearance > Editor > Theme Functions (functions.php). Place the following code in the bottom your functions file and hit “Update File.”
add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2); function add_login_logout_link($items, $args) { ob_start(); wp_loginout('index.php'); $loginoutlink = ob_get_contents(); ob_end_clean(); $items .= '<li>'. $loginoutlink .'</li>'; return $items; }
The Result
Keep in mind that these links will appear wherever you put your custom menus – be they at the top of your page, in your sidebar, or anywhere else.
Photo: login icon from BigStock
'WEB > WP(WordPress)' 카테고리의 다른 글
How to override the woocommerce.css in the parent theme? (0) | 2019.03.05 |
---|---|
Does Wordpress Provide Native Datepicker in Admin? (0) | 2018.06.04 |
Checking if Database Table Exists in WordPress (0) | 2018.05.17 |
PHP Fatal error: Cannot redeclare eto_shortcode_image() Trouble Shoot (0) | 2018.04.28 |
A Quick and Easy Guide To Creating WordPress Admin Pages (0) | 2018.04.27 |