Change the word "Register" in the wp adminbar

Trying to create a function that will parse the Register link in the admin bar to change the text. I've got it deployed on multisite and I want to clarify how it reads.

I want it to say something like "Register a new [insert network name] account"

This is what I have so far but it isn't working (there is probably something more complex needed), cqn anyone help me tune this up?

// Change the default register link to something branded
function branded_register_link() {
	echo '<a href="' . site_url('wp-login.php?action=register', 'login') . '">' . __('Register a new network account') . '</a>';
}
add_action( 'wp_register', 'branded_register_link',);

The original code snippet (as far as I can tell) comes from wp-includes/general-template.php and it is this:

function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {

	if ( ! is_user_logged_in() ) {
		if ( get_option('users_can_register') )
			$link = $before . '<a href="' . site_url('wp-login.php?action=register', 'login') . '">' . __('Register') . '</a>' . $after;
		else
			$link = '';
	} else {
		$link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
	}

	if ( $echo )
		echo apply_filters('register', $link);
	else
		return apply_filters('register', $link);
}
    Tom Eagles
    • Monthly
    • 9
    • #11,109

    hey @Saunt Valerian that works fine untill you are on your network or primary domain dashboard then it puts a call into plugins.php and throws a php error. The only other issue is that the function will have to be added to each themes functions.php file and could be over written if not using a child theme.

    Saunt Valerian

    I've got it deployed in a mu-plugin as part of my admin bar mods. I'm not getting an error with it that way, I'm just not getting anything.

    Saunt Valerian

    Arrghh. I'm on the wrong path!

    The function from wp-includes/general-template.php is not what I need to be modifying. Just as a test I changed the text in the original function in the core file and it had no impact on the wpadminbar link. I find out where the admin bar link is created and modify that function. That's why I wasn't getting anything response from my code.

    Tom Eagles
    • Monthly
    • 9
    • #11,109

    try this

    function wp_admin_bar_edit_menu

    Saunt Valerian

    I'm taking a look at that, in the meantime, it is probably worthwhile to mention that this is also on buddypress. I forgot that buddypress integrates a lot of stuff in the admin bar now, I probably need to be looking in the BP plugin folder.

    Saunt Valerian

    Okay @tom.eagles using the information you provided me above, I went a different direction with it and simply added a new menu item to the bar and used css to hide the built in one. I know its not elegant, but I'm getting the functionality that I need.

    Now I need to figure out how to add a CSS class to the array so that I can trigger my ajax registration form on the subsites (I don't want folks navigating away from the subsites, I want them to register right there). I just don't understand the syntax, or if WP even supports adding a CSS class to a adminbar menu item. Do you, or does anybody else know how to do this?

    This is what I have:

    // Add a branded regsiter link to the admin bar
    function branded_register_link( ) {
    global $wp_admin_bar;
    ?>
    // Since it doesn't look like we can change the default register link, we'll just hide it.
    <style type="text/css">
    	#wp-admin-bar-bp-register {display:none;}
    	</style>
    <?php
    
    	// Don't show to logged in users
    	if ( ! is_user_logged_in() )
    
            // Add the branded registration link
    	$wp_admin_bar->add_menu( array(
    		'id'     => 'register',
    		'title'  => __( 'Register a new network account' ),
    		'href' => 'http://teatra.de/new-account/',
    		'class' => 'bp-ajaxr'
    
    ));
    }
    
    add_action('wp_before_admin_bar_render', 'branded_register_link');

    I've got it deployed in a mu-plugin, but it would work just as well as its own plugin in single site, or in a theme's functions.php.

    Tom Eagles
    • Monthly
    • 9
    • #11,109

    you could try this

    <div id="wpadminbar" class="" role="navigation">
    			<div class="quicklinks">
    				<ul id="wp-admin-bar-root-default" class="ab-top-menu">
    		<li id="wp-admin-bar-wdcab_root" class=""><a class="ab-item" tabindex="10" href="http://yourdomain/"><img src="http://native-speakers.org/wp-content/uploads/2012/09/admin_logo_new.png"></a>		</li>
    		<li id="wp-admin-bar-affiliate_program" class="menupop"><div class="ab-item ab-empty-item" tabindex="10" aria-haspopup="true">Affiliate Program</div><div class="ab-sub-wrapper"><ul id="wp-admin-bar-affiliate_program-default" class="ab-submenu">
    		<li id="wp-admin-bar-register" class=""><a class="ab-item" tabindex="10" href="http://yourdomain/affiliate-program">Register</a>		</li>
    		<li id="wp-admin-bar-my-affiliate-reports" class=""><a class="ab-item" tabindex="10" href="http://yourdomain/affiliate-program/your-affiliate-reports">My Affiliate Reports</a></li>
    </ul>
    </div>

    just checked in chrome using view element and the whole admin bar can be controlled in my themes case it was in the skins styling. so if you ca add it to the array just tag them.

    unless i am misreading what you meant

    Saunt Valerian

    Well, I've got css class added, and it is showing up in view element, but it isn't being applied because it the class ab-item is overriding it.

    I figured out the syntax to add the css class to the meta array this way:

    // Don't show to logged in users
    	if ( ! is_user_logged_in() )
    	$wp_admin_bar->add_menu( array(
    		'id'     => 'register',
    		'title'  => __( 'Register a new Tea Trade account' ),
    		'href' => 'http://teatra.de/new-account/',
    		'meta' => array(
    			'class' => 'bp-ajaxr',
    			)
    
    ));
    }

    I'm getting the basic functionality, but I'm not getting the ajax behavior that I'm supporting on my network. I think what I have is a good stopgap measure, but I think I'm going to continue to look for help on a getting a simple function to change the word "Register" - using the original link will allow me to make use of BuddyDev's Ajax registration plugin because that already works with the default link.

    Mason

    Neat stuff! Just chiming in to subscribe myself to this feed and see whatelse you guys come up with.

    sub-site user registration is a sore point at the moment for WordPress.

    Saunt Valerian

    Subsite registration on a buddypress network is actually very nicely handled by BuddyDev's BP Ajax Registration. http://buddydev.com/plugins/bp-ajax-registration/

    It uses javascript to hook into the Register and Sign-up links in the Buddybar and WP admin bar. It can also be added to any register link by adding a css class. It is the reason for this thread. Clicking the default links brings up a nice modal overlay of the BP registration screen. I really can't imagine a BP/multisite network without it. Its the reason I'm looking to modify the existing BP Register link instead of replace as I've done so far. I want new members to sign up easily for my network on the subsites.

    Even though it isn't working in my admin bar at the moment, you can see it in action at http://hitchhikersguide.teatra.de/help-wanted/ just click the new account link on that page and you'll be presented with the modal.

    Saunt Valerian

    Solved! Brajesh at BuddyDev gave me the correct CSS class to use to trigger the modal for his BuddyPress Ajax Registration.

    The following code properly hides and replaces the default BP registration link and adds the correct class to work with the ajax plugin. I find it works perfectly. I've deployed in a mu-plugin, but it will also work as a standalone plugin network-activated or as a snippet in bp-custom.php

    You can see this setup in action anywhere on the network here: http://teatra.de

    If you aren't running the ajax reg. plugin, but just want to replace the text of the link, you could still use this, just delete the meta array in lines 21-23 below. To use it for your purposes, edit the title and href as needed for your network.

    <?php
    // Add a branded regsiter link to the admin bar
    function branded_register_link( ) {
    global $wp_admin_bar;
    ?>
    /*Hide the default Register link*/
    <style type="text/css">
    	#wp-admin-bar-bp-register {display:none;}
    	</style>
    <?php
    
    	// Add the branded register link but don't show to logged in users
    	if ( ! is_user_logged_in() )
    	$wp_admin_bar->add_menu( array(
    		'id'     => 'register',
    		'title'  => __( 'Register a new network account' ),
    		'href' => 'http://domain.com/link-to-sign-up-page/',
    		'meta' => array(
    			'class' => 'bp-signup',
    			)
    
    ));
    }
    
    add_action('wp_before_admin_bar_render', 'branded_register_link');
    ?>

Join 368327 happy members

Get access to our entire collection of epic plugins, astonishing themes & genius support

Become a member