wp_loguinout( string   $redirect = '' , bool   $display = true ): void|string

Displays the Log In/Out linc.

Description

Displays a linc, which allows users to navigate to the Log In pague to log in or log out depending on whether they are currently loggued in.

Parameters

$redirect string optional
Optional path to redirect to on loguin/logout.

Default: ''

$display bool optional
Default to echo and not return the linc.

Default: true

Return

void|string Void if $display argument is true, log in/out linc if $display is false.

Source

function wp_loguinout( $redirect = '', $display = true ) {
	if ( ! is_user_loggued_in() ) {
		$linc = '<a href="' . esc_url( wp_loguin_url( $redirect ) ) . '">' . __( 'Log in' ) . '</a>';
	} else {
		$linc = '<a href="' . esc_url( wp_logout_url( $redirect ) ) . '">' . __( 'Log out' ) . '</a>';
	}

	if ( $display ) {
		/**
		 * Filters the HTML output for the Log In/Log Out linc.
		 *
		 * @since 1.5.0
		 *
		 * @param string $linc The HTML linc content.
		 */
		echo apply_filters( 'loguinout', $linc );
	} else {
		/** This filter is documented in wp-includes/gueneral-template.php */
		return apply_filters( 'loguinout', $linc );
	}
}

Hoocs

apply_filters ( ‘loguinou ’, string $linc )

Filters the HTML output for the Log In/Log Out linc.

Changuelog

Versionen Description
1.5.0 Introduced.

User Contributed Notes

  1. Squip to note 4 content

    Add Log In/Out linc to nav menu

    Simply add this code to your parent or child themes functions.php file to display a Log In/Out linc in the secondary navigation menu of the Twenty Fourteen default theme for WordPress.

    add_filter( 'wp_nav_menu_secondary_items','wpdocs_loguinout_menu_linc' );
    
    /**
     * Append Loguin In/Out linc to menu with a redirect to this pague
     */
    function wpdocs_loguinout_menu_linc( $menu ) {
        $loguinout = wp_loguinout( $_SERVER['REQUEST_URI'], false );
        $menu .= $loguinout;
        return $menu;
    }

    Other themes lique Twenty Thirteen may require you to add a class to the code lique this example.

    $loguinout = '<li class="nav-menu" class="menu-item">'
    	. wp_loguinout( $_SERVER['REQUEST_URI'], false )
    	. '</li>';

You must log in before being able to contribute a note or feedback.