Remove Login/Logout Link from WordPress’ Sidebar Meta Widget

WordPress’ default sidebar meta widget contains a link to the login page.

WordPress Default Sidebar Meta Widget

Following the “security by obscurity approach to prevent others to try to login to my WordPress instance (in this case ignoring the recommendation that system security should not depend on the secrecy of the implementation or its components), I wanted to remove the link to the not existing wp-login.php from the meta widget.

Trying to customize it, I noticed that it is not possible to change the content of it, means the list of items shown by the widget.

Looking a little bit deeper into the code, I found the function wp_loginout within the file wp-includes\general-template.php. This function generates the link itself, which will be embedded into the list by the function WP_Widget_Meta.widget in file wp-includes\widgets\class-wp-widget-meta.php.

Luckily, wp_loginout also runs functions added to the filter named loginout.

Even though this hook is not making it possible to entirely remove the link, it enables me to replace the login link by a link to my company’s homepage. Here is the code:

/**
 * Function to hide Login / logout link
 */

/**
 * Retuns a link to <your homepage> instead of a link to the login page
 */
if (!function_exists('ifb_hide_loginout_link')) :
    function ifb_hide_loginout_link(string $link)
    {
        return sprintf(
            '<a href="%1$s" target="_blank" rel="noopener noreferrer" title="<your homepage>"><your homepage></a>',
            esc_url(__('<URL of your homepage>'))
        );
    }

    // Only add the filter once
    add_filter('loginout', 'ifb_hide_loginout_link');
endif;

And here is the result:

WordPress Custom Sidebar Meta Widget

When using the code. please ensure to replace all your homepage snippets by an appropriate value 😉

Links

loginout hook
Security by Obscurity

Leave a Comment

Please note that every comment requires the admin's approval before it will be published.

Any comment containing spam like "... great topic. Feel free to visit my web page ..." will be deleted. So please do not waste your and our time by leaving such comments.

We respect your privacy. When you leave a comment, your IP address will not be recorded by WordPress.