Title: Hack/Function for General-Template.php
Last modified: August 30, 2016

---

# Hack/Function for General-Template.php

 *  Resolved [Dono12](https://wordpress.org/support/users/dono12/)
 * (@dono12)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/hackfunction-for-general-templatephp/)
 * Can anyone tell me how to write a custom function for my functions.php for this
   block of code. I don’t want lose it in the next WordPress Update? This code comes
   from gemneral-template.php. It is for the Meta widget REGISTER/LOGIN LOGOUT I
   replaced the ADMIN link to show User Profile. SO when user is logged in they 
   click profile and it takes them to Buddypress Profile.
 *     ```
       function wp_register( $before = '
   
       ', $after = '
       ', $echo = true ) {
       if ( ! is_user_logged_in() ) {
       if ( get_option('users_can_register') )
       $link = $before . '' . __('Register') . '' . $after;
       else
       $link = '';
       } else {
       $link = $before . ' ' . __('User Profile', 'buddypress') . '' . $after;
       }
       ```
   

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Moderator [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/)
 * (@jcastaneda)
 * THEME COFFEE MONKEY
 * [10 years, 7 months ago](https://wordpress.org/support/topic/hackfunction-for-general-templatephp/#post-6616464)
 * Hey Dono12!
 * What worries me is that you say you don’t want to lose it in the next update 
   of WordPress. Have you edited the core file ( `general-template.php` ) to read
   that or you using that particular code in a plugin/theme?
 * I’m not sure if you are aware of functionality plugins but you may want to look
   into them. What’s neat is that WordPress does have some great hooks and filters
   so that you can modify how some things look and act. The `wp_register` function
   is one.
 * If you look at line 535 of that file:
    link: [https://core.trac.wordpress.org/browser/tags/4.3.1/src/wp-includes/general-template.php#L535](https://core.trac.wordpress.org/browser/tags/4.3.1/src/wp-includes/general-template.php#L535)
 *     ```
       $link = apply_filters( 'register', $link );
       ```
   
 * What this means is you can do something like:
 *     ```
       add_filter( 'register', 'my_custom_register_thingy' );
       function my_custom_register_thingy( $link ){
       	if ( ! is_user_logged_in() ) {
       		if ( get_option('users_can_register') )
       			$link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __('Register', 'text-domain') . '</a>' . $after;
       		else
       			$link = '';
       	} elseif ( current_user_can( 'read' ) ) {
       		$link = $before . '<a href="' . admin_url() . '">' . __('Site Admin', 'text-domain') . '</a>' . $after;
       	} else {
       		$link = '';
       	}
       ```
   
 * That is a quick example of how you can do it; I am currently not able to test
   that but feel free to dabble with that to suit your needs. 🙂
 *  Thread Starter [Dono12](https://wordpress.org/support/users/dono12/)
 * (@dono12)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/hackfunction-for-general-templatephp/#post-6616510)
 * It was an edit to the core file general-template.php. Not a plugin. Thanks for
   your help by the way, but the code above gave me the white screen of death when
   I placed it in functions.php. I think there’s also an extra bracket in the code
   you gave me. I tried removing one of the brackets and still got the white screen:(.
   Any further assistance would be greatly appreciated.
 *  Moderator [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/)
 * (@jcastaneda)
 * THEME COFFEE MONKEY
 * [10 years, 7 months ago](https://wordpress.org/support/topic/hackfunction-for-general-templatephp/#post-6616536)
 * Wow, didn’t realize I missed the closing bracket for the function. 🙁
 * And that’s why I need to be drinking my coffee. Helps me focus. 🙂
 *  Thread Starter [Dono12](https://wordpress.org/support/users/dono12/)
 * (@dono12)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/hackfunction-for-general-templatephp/#post-6616572)
 * It still doesn’t work. This is what I have::::
 *     ```
       function my_custom_register( $link ){
       	if ( ! is_user_logged_in() ) {
       		if ( get_option('users_can_register') )
       			$link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __('Register', 'buddypress') . '</a>' . $after;
       		else
       			$link = '';
       	} elseif ( current_user_can( 'read' ) ) {
       		$link = $before . '<a href="' . bp_loggedin_user_domain('/') . "profile" . '">' . __('User Profile', 'buddypress') . '</a>' . $after;
       	} else {
       		$link = '';
       	}
       }
   
       	add_filter( 'register', 'my_custom_register' );
       ```
   
 * If I change general-template.php to its original coding
 * `$link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a
   >' . $after;`
 * and place the custom function you gave me into my functions.php, I still get 
   Site-Admin in the sidebar Widget area.
 *  Moderator [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/)
 * (@jcastaneda)
 * THEME COFFEE MONKEY
 * [10 years, 7 months ago](https://wordpress.org/support/topic/hackfunction-for-general-templatephp/#post-6616573)
 * Just before the closing bracket add:
 *     ```
       if ( $echo ) {
       	echo $link;
       } else {
       	return $link;
       }
       ```
   
 *  Thread Starter [Dono12](https://wordpress.org/support/users/dono12/)
 * (@dono12)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/hackfunction-for-general-templatephp/#post-6616591)
 * It worked like a charm. Thanks a lot Jose.
 *  Moderator [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/)
 * (@jcastaneda)
 * THEME COFFEE MONKEY
 * [10 years, 7 months ago](https://wordpress.org/support/topic/hackfunction-for-general-templatephp/#post-6616592)
 * Of course! Happy to help! 🙂

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Hack/Function for General-Template.php’ is closed to new replies.

## Tags

 * [login](https://wordpress.org/support/topic-tag/login/)
 * [profile](https://wordpress.org/support/topic-tag/profile/)
 * [register](https://wordpress.org/support/topic-tag/register/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 7 replies
 * 2 participants
 * Last reply from: [Jose Castaneda](https://wordpress.org/support/users/jcastaneda/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/hackfunction-for-general-templatephp/#post-6616592)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
