The loginout WordPress PHP Filter allows you to modify the HTML output for the Log In/Log Out link.
Usage
add_filter('loginout', 'your_custom_function');
function your_custom_function($link) {
// your custom code here
return $link;
}
Parameters
- $link (string): The HTML link content.
More information
See WordPress Developer Resources: loginout
Examples
Add a custom class to the link
Add a custom class “my-custom-class” to the Log In/Log Out link.
add_filter('loginout', 'add_custom_class_to_loginout');
function add_custom_class_to_loginout($link) {
$link = str_replace('<a ', '<a class="my-custom-class" ', $link);
return $link;
}
Change the Log In and Log Out text
Change the text for the Log In and Log Out links to “Sign In” and “Sign Out”.
add_filter('loginout', 'change_loginout_text');
function change_loginout_text($link) {
$link = str_replace('Log In', 'Sign In', $link);
$link = str_replace('Log Out', 'Sign Out', $link);
return $link;
}
Add a custom icon to the Log In and Log Out links
Add a custom icon (FontAwesome) to the Log In and Log Out links.
add_filter('loginout', 'add_icon_to_loginout');
function add_icon_to_loginout($link) {
$login_icon = '<i class="fas fa-sign-in-alt"></i> ';
$logout_icon = '<i class="fas fa-sign-out-alt"></i> ';
$link = str_replace('Log In', $login_icon . 'Log In', $link);
$link = str_replace('Log Out', $logout_icon . 'Log Out', $link);
return $link;
}
Add a “Welcome, username” message before the Log Out link
Add a “Welcome, username” message before the Log Out link.
add_filter('loginout', 'add_welcome_message');
function add_welcome_message($link) {
if (is_user_logged_in()) {
$current_user = wp_get_current_user();
$link = 'Welcome, ' . $current_user->display_name . ' | ' . $link;
}
return $link;
}
Remove the “Log In” link and only display “Log Out” link
Remove the “Log In” link and only display the “Log Out” link when the user is logged in.
add_filter('loginout', 'remove_login_link');
function remove_login_link($link) {
if (!is_user_logged_in()) {
$link = '';
}
return $link;
}