wp_loginout

The timeline below displays how wordpress function wp_loginout has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Displays the Log In/Out link.
 *
 * Displays a link, which allows users to navigate to the Log In page to log in
 * or log out depending on whether they are currently logged in.
 *
 * @since 1.5.0
 *
 * @param string $redirect Optional path to redirect to on login/logout.
 * @param bool   $display  Default to echo and not return the link.
 * @return void|string Void if `$display` argument is true, log in/out link if `$display` is false.
 */
function wp_loginout($redirect = '', $display = true)
{
    if (!is_user_logged_in()) {
        $link = '<a href="' . esc_url(wp_login_url($redirect)) . '">' . __('Log in') . '</a>';
    } else {
        $link = '<a href="' . esc_url(wp_logout_url($redirect)) . '">' . __('Log out') . '</a>';
    }
    if ($display) {
        /**
         * Filters the HTML output for the Log In/Log Out link.
         *
         * @since 1.5.0
         *
         * @param string $link The HTML link content.
         */
        echo apply_filters('loginout', $link);
    } else {
        /** This filter is documented in wp-includes/general-template.php */
        return apply_filters('loginout', $link);
    }
}

WordPress Version: 6.1

/**
 * Displays the Log In/Out link.
 *
 * Displays a link, which allows users to navigate to the Log In page to log in
 * or log out depending on whether they are currently logged in.
 *
 * @since 1.5.0
 *
 * @param string $redirect Optional path to redirect to on login/logout.
 * @param bool   $echo     Default to echo and not return the link.
 * @return void|string Void if `$echo` argument is true, log in/out link if `$echo` is false.
 */
function wp_loginout($redirect = '', $echo = true)
{
    if (!is_user_logged_in()) {
        $link = '<a href="' . esc_url(wp_login_url($redirect)) . '">' . __('Log in') . '</a>';
    } else {
        $link = '<a href="' . esc_url(wp_logout_url($redirect)) . '">' . __('Log out') . '</a>';
    }
    if ($echo) {
        /**
         * Filters the HTML output for the Log In/Log Out link.
         *
         * @since 1.5.0
         *
         * @param string $link The HTML link content.
         */
        echo apply_filters('loginout', $link);
    } else {
        /** This filter is documented in wp-includes/general-template.php */
        return apply_filters('loginout', $link);
    }
}

WordPress Version: 5.4

/**
 * Display the Log In/Out link.
 *
 * Displays a link, which allows users to navigate to the Log In page to log in
 * or log out depending on whether they are currently logged in.
 *
 * @since 1.5.0
 *
 * @param string $redirect Optional path to redirect to on login/logout.
 * @param bool   $echo     Default to echo and not return the link.
 * @return void|string Void if `$echo` argument is true, log in/out link if `$echo` is false.
 */
function wp_loginout($redirect = '', $echo = true)
{
    if (!is_user_logged_in()) {
        $link = '<a href="' . esc_url(wp_login_url($redirect)) . '">' . __('Log in') . '</a>';
    } else {
        $link = '<a href="' . esc_url(wp_logout_url($redirect)) . '">' . __('Log out') . '</a>';
    }
    if ($echo) {
        /**
         * Filters the HTML output for the Log In/Log Out link.
         *
         * @since 1.5.0
         *
         * @param string $link The HTML link content.
         */
        echo apply_filters('loginout', $link);
    } else {
        /** This filter is documented in wp-includes/general-template.php */
        return apply_filters('loginout', $link);
    }
}

WordPress Version: 4.6

/**
 * Display the Log In/Out link.
 *
 * Displays a link, which allows users to navigate to the Log In page to log in
 * or log out depending on whether they are currently logged in.
 *
 * @since 1.5.0
 *
 * @param string $redirect Optional path to redirect to on login/logout.
 * @param bool   $echo     Default to echo and not return the link.
 * @return string|void String when retrieving.
 */
function wp_loginout($redirect = '', $echo = true)
{
    if (!is_user_logged_in()) {
        $link = '<a href="' . esc_url(wp_login_url($redirect)) . '">' . __('Log in') . '</a>';
    } else {
        $link = '<a href="' . esc_url(wp_logout_url($redirect)) . '">' . __('Log out') . '</a>';
    }
    if ($echo) {
        /**
         * Filters the HTML output for the Log In/Log Out link.
         *
         * @since 1.5.0
         *
         * @param string $link The HTML link content.
         */
        echo apply_filters('loginout', $link);
    } else {
        /** This filter is documented in wp-includes/general-template.php */
        return apply_filters('loginout', $link);
    }
}

WordPress Version: 4.3

/**
 * Display the Log In/Out link.
 *
 * Displays a link, which allows users to navigate to the Log In page to log in
 * or log out depending on whether they are currently logged in.
 *
 * @since 1.5.0
 *
 * @param string $redirect Optional path to redirect to on login/logout.
 * @param bool   $echo     Default to echo and not return the link.
 * @return string|void String when retrieving.
 */
function wp_loginout($redirect = '', $echo = true)
{
    if (!is_user_logged_in()) {
        $link = '<a href="' . esc_url(wp_login_url($redirect)) . '">' . __('Log in') . '</a>';
    } else {
        $link = '<a href="' . esc_url(wp_logout_url($redirect)) . '">' . __('Log out') . '</a>';
    }
    if ($echo) {
        /**
         * Filter the HTML output for the Log In/Log Out link.
         *
         * @since 1.5.0
         *
         * @param string $link The HTML link content.
         */
        echo apply_filters('loginout', $link);
    } else {
        /** This filter is documented in wp-includes/general-template.php */
        return apply_filters('loginout', $link);
    }
}

WordPress Version: 3.9

/**
 * Display the Log In/Out link.
 *
 * Displays a link, which allows users to navigate to the Log In page to log in
 * or log out depending on whether they are currently logged in.
 *
 * @since 1.5.0
 *
 * @param string $redirect Optional path to redirect to on login/logout.
 * @param boolean $echo Default to echo and not return the link.
 * @return string|null String when retrieving, null when displaying.
 */
function wp_loginout($redirect = '', $echo = true)
{
    if (!is_user_logged_in()) {
        $link = '<a href="' . esc_url(wp_login_url($redirect)) . '">' . __('Log in') . '</a>';
    } else {
        $link = '<a href="' . esc_url(wp_logout_url($redirect)) . '">' . __('Log out') . '</a>';
    }
    if ($echo) {
        /**
         * Filter the HTML output for the Log In/Log Out link.
         *
         * @since 1.5.0
         *
         * @param string $link The HTML link content.
         */
        echo apply_filters('loginout', $link);
    } else {
        /** This filter is documented in wp-includes/general-template.php */
        return apply_filters('loginout', $link);
    }
}

WordPress Version: 3.7

/**
 * Display the Log In/Out link.
 *
 * Displays a link, which allows users to navigate to the Log In page to log in
 * or log out depending on whether they are currently logged in.
 *
 * @since 1.5.0
 * @uses apply_filters() Calls 'loginout' hook on HTML link content.
 *
 * @param string $redirect Optional path to redirect to on login/logout.
 * @param boolean $echo Default to echo and not return the link.
 * @return string|null String when retrieving, null when displaying.
 */
function wp_loginout($redirect = '', $echo = true)
{
    if (!is_user_logged_in()) {
        $link = '<a href="' . esc_url(wp_login_url($redirect)) . '">' . __('Log in') . '</a>';
    } else {
        $link = '<a href="' . esc_url(wp_logout_url($redirect)) . '">' . __('Log out') . '</a>';
    }
    if ($echo) {
        echo apply_filters('loginout', $link);
    } else {
        return apply_filters('loginout', $link);
    }
}