Placing Template FilesCustomizing Template Filesgravityformsuserregistration-login.php examplegravityformsuserregistration-loggedin.php example
If you』re using the Gravity Forms login form but want to use a custom template, you can easily do so. This is especially helpful for theme developers who want to utilize the existing login form already built into Gravity Forms.
Placing Template Files
The Gravity Forms login form can be customized by placing template files directly within your active theme. If the login form is being loaded, Gravity Forms will automatically load those template files when needed. Here are the files it will look for:
gravityformsuserregistration-login.php
This template file is loaded when the login form is displayed, and the user is not logged in.
gravityformsuserregistration-loggedin.php
If the user is already logged in, this template will be loaded.
Both of these files will need to be placed in the top-level of your active theme. Outside of placing the files there, no additional configuration is needed. If the file exists, it will be used.
Customizing Template Files
When using these custom template files, the sky is the limit! Inside the template, you can load any code or output any markup that you need.
Keep in mind that these files will override the default markup automatically even if they』re blank, so be sure to include things like username and password fields if you still need to use them.
To help you start below you can find example content for both files that reproduce the default markup.
gravityformsuserregistration-login.php example
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081// Just a title to let you know the custom template is being loaded. Remove before going live.echo '
This is my custom Login Form - Not logged template
'; extract( $args ); /* Get the login form. */$form = GF_User_Registration::login_form_object(); /* Set the tab index. */GFCommon::$tab_index = gf_apply_filters( array( 'gform_tabindex', $form['id'] ), $tabindex, $form ); /* Enqueue needed scripts. */GFFormDisplay::enqueue_form_scripts( $form, false ); /* Prepare the form wrapper class. */$wrapper_css_class = GFCommon::get_browser_class() . ' gform_wrapper'; /* Ensure login redirect URL isn't empty. */if ( rgblank( $login_redirect ) ) { $login_redirect = ( isset( $_SERVER['HTTPS'] ) ? 'https' : 'http' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];} /* Open Gravity Form wrapper and form tag. */$html = "
';$html .= '
'; /* Display links. */if ( ! empty( $logged_out_links ) ) { if ( GF_User_Registration::get_plugin_setting( 'custom_registration_page_enable' ) == '1' ) { $registration_page = GF_User_Registration::get_plugin_setting( 'custom_registration_page' ); $register_url = 'gf_custom' === $registration_page ? GF_User_Registration::get_plugin_setting( 'custom_registration_page_custom' ) : get_permalink( $registration_page ); } else { $register_url = wp_registration_url(); } $html .= '
'; } echo $html;
gravityformsuserregistration-loggedin.php example
1234567891011121314151617181920212223242526272829303132333435// Just a title to let you know the custom template is being loaded. Remove before going live.echo '
This is my custom Login Form - Logged in template
'; /* Prepare the logged in message. */if ( rgblank( $logged_in_message ) ) { $logged_in_message = sprintf( esc_html__( 'You are currently logged in as %s%s%s. %sLog out?%s', 'gravityformsuserregistration' ), '', $current_user->display_name, '', '', '' );} else { $logged_in_message = str_replace( '{logout_url}', '' . esc_html__( 'Logout', 'gravityformsuserregistration' ) . '', $logged_in_message ); $logged_in_message = GFCommon::replace_variables( $logged_in_message, array(), array(), false, false, false, 'text' );} /* Display the avatar and logged in message. */$html = '
';$html .= filter_var( $logged_in_avatar, FILTER_VALIDATE_BOOLEAN ) ? get_avatar( $current_user->ID ) . '
' : null;$html .= $logged_in_message;$html .= '
'; /* Display links. */if ( ! empty( $logged_in_links ) ) { foreach ( $logged_in_links as $link ) { $link['url'] = str_replace( '{logout_url}', esc_attr( wp_logout_url( $logout_redirect ) ), $link['url'] ); $link['url'] = GFCommon::replace_variables( $link['url'], array(), array(), false, false, false, 'text' ); $html .= '' . esc_html( $link['text'] ) . '
'; } } echo $html;