wp_register( string $before = ‘<li>’, string $after = ‘</li>’, bool $display = true ): void|string

Displays the Registration or Admin link.

Description

Display a link which allows the user to navigate to the registration page if not logged in and registration is enabled or to the dashboard if logged in.

Parameters

$beforestringoptional
Text to output before the link. Default <li>.

Default:'<li>'

$afterstringoptional
Text to output after the link. Default </li>.

Default:'</li>'

$displaybooloptional
Default to echo and not return the link.

Default:true

Return

void|string Void if $display argument is true, registration or admin link if $display is false.

More Information

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

Source

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;
	}
}

Hooks

apply_filters( ‘register’, string $link )

Filters the HTML link to the Registration or Admin page.

Changelog

VersionDescription
1.5.0Introduced.

User Contributed Notes

  1. Skip to note 4 content

    Display Without Text Before or After
    The following code example displays the “Register” or “Site Admin” link with no text in before or after parameters.

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

    When not logged in the following HTML is produced:

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

    When logged in the following HTML is produced:

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

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