wp_register()WP 1.5.0

Displays either the link to the dashboard ("Site Admin") if the user is logged in or "Register" link if the user is not logged in.

The "Register" link is not offered if the Administration > Settings > General > Membership: Anyone can register box is not checked.

1 time — 0.000127 sec (fast) | 50000 times — 3.03 sec (fast)
Hooks from the function

Return

null|String. Void if $display argument is true, registration or admin link if $display is false.

Usage

wp_register( $before, $after, $display );
$before(string)
Text to output before the link.
Default: <li>
$after(string)
Text to output after the link.
Default: </li>
$display(true|false)
Default to echo and not return the link.
Default: true

Examples

0

#1 Display a link to the admin panel or registration page

The link will be wrapped in <li> tag:

wp_register();
/* output: 
<li>
	<a href="/wp-admin/">Site Admin</a>
</li>
*/
0

#2 Without "before" and "after" text

This example will output a link without a wrapping <li> tag:

<?php wp_register('', ''); ?>

In the result, we will get this link if not logged in:

<a href="http://example.com/wp-login.php?action=register">Register</a>

Or this one if logged in:

<a href="http://example.com/wp-admin/">Site Admin</a>

Changelog

Since 1.5.0 Introduced.

wp_register() code WP 6.4.3

function wp_register( $before = '<li>', $after = '</li>', $display = true ) {
	if ( ! is_user_logged_in() ) {
		if ( get_option( 'users_can_register' ) ) {
			$link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __( 'Register' ) . '</a>' . $after;
		} else {
			$link = '';
		}
	} elseif ( current_user_can( 'read' ) ) {
		$link = $before . '<a href="' . admin_url() . '">' . __( 'Site Admin' ) . '</a>' . $after;
	} else {
		$link = '';
	}

	/**
	 * Filters the HTML link to the Registration or Admin page.
	 *
	 * Users are sent to the admin page if logged-in, or the registration page
	 * if enabled and logged-out.
	 *
	 * @since 1.5.0
	 *
	 * @param string $link The HTML code for the link to the Registration or Admin page.
	 */
	$link = apply_filters( 'register', $link );

	if ( $display ) {
		echo $link;
	} else {
		return $link;
	}
}