WordPress at a glance

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.000127s = fast | 50000 times = 3.03s = fast
Hooks in function
Return

String/null. String when retrieving.

Usage

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

Examples

#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>
*/

#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>

Code of wp register: wp-includes/general-template.php WP 5.2.2

<?php
function wp_register( $before = '<li>', $after = '</li>', $echo = 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 ( $echo ) {
		echo $link;
	} else {
		return $link;
	}
}

Related Functions

From tag: Link (tag A in HTML)

More from category: Login/Logout

More from Template Tags: Main Functions

No comments
    Hello, !     Log In . Register