Theme My Login Shortcode

Below, you’ll find a detailed guide on how to add the Theme My Login Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Theme My Login Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Theme My Login Plugin and the shortcodes it provides:

Plugin Icon
Theme My Login

"Theme My Login is a powerful WordPress plugin that allows you to customize your login, registration, and password recovery pages to match your theme for a seamless user experience."

★★★☆✩ (456) Active Installs: 90000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [theme-my-login]

Theme My Login [theme-my-login] Shortcode

The Theme-My-Login shortcode is a powerful tool that allows you to customize user actions. It provides options to specify default actions, show links, and set redirection paths. The shortcode function ‘tml_shortcode’ takes in attributes and processes them. If no action is specified, it defaults to the ‘login’ action. It also allows for customization of the login form and dashboard view. The shortcode ensures a smooth user experience, with options for account request confirmation and user-specific dashboard greetings. It also provides easy access to important links like ‘Site Admin’, ‘Edit Profile’, and ‘Log Out’. In conclusion, the Theme-My-Login shortcode is a versatile tool for enhancing user interaction and experience on your WordPress site.

Shortcode: [theme-my-login]

Parameters

Here is a list of all possible theme-my-login shortcode parameters and attributes:

  • default_action – Defines the initial action of the login form.
  • action – Determines the specific action of the form.
  • show_links – Controls the visibility of form links.
  • redirect_to – Specifies the URL to redirect after form submission.

Examples and Usage

Basic example – A simple usage of the theme-my-login shortcode without any parameters. This will default to the login action.

[theme-my-login /]

Advanced examples

Using the shortcode to display a login form with links to registration and lost password page. The ‘show_links’ attribute is set to true.

[theme-my-login show_links="true" /]

Using the shortcode to display a login form with a specific redirection after login. The ‘redirect_to’ attribute is used to specify the URL to redirect to after login.

[theme-my-login redirect_to="https://www.example.com/dashboard" /]

Using the shortcode to display a specific action form. The ‘action’ attribute is used to specify the action form to display. Possible actions include ‘login’, ‘register’, ‘lostpassword’, ‘resetpass’, and ‘confirmaction’.

[theme-my-login action="register" /]

Combining multiple attributes to display a register form with links and a specific redirection after registration.

[theme-my-login action="register" show_links="true" redirect_to="https://www.example.com/welcome" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [theme-my-login] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'theme-my-login', 'tml_shortcode' );

Shortcode PHP function:

function tml_shortcode( $atts = array() ) {
	$atts = (array) $atts;

	if ( isset( $atts['default_action'] ) ) {
		$atts['action'] = $atts['default_action'];
	}

	$atts = shortcode_atts( array(
		'action'      => '',
		'show_links'  => null,
		'redirect_to' => null,
	), $atts, 'theme-my-login' );

	$content = '';

	if ( empty( $atts['action'] ) ) {
		$action = tml_is_action() ? tml_get_action() : tml_get_action( 'login' );
	} elseif ( ! $action = tml_get_action( $atts['action'] ) ) {
		return $content;
	}

	if ( $form = tml_get_form( $action->get_name() ) ) {

		$args = array();

		if ( null !== $atts['show_links'] ) {
			$args['show_links'] = (bool) $atts['show_links'];
		}

		if ( null !== $atts['redirect_to'] ) {
			if ( $redirect_to = $form->get_field( 'redirect_to' ) ) {
				$redirect_to->set_value( $atts['redirect_to'] );
			}
			unset( $redirect_to );
		}

		$content = $form->render( $args );

	} elseif ( 'confirmaction' == $action->get_name() && isset( $_GET['request_id'] ) ) {
		$content = _wp_privacy_account_request_confirmed_message( $_GET['request_id'] );

	} elseif ( 'dashboard' == $action->get_name() ) {
		$content = '<div class="tml-dashboard">';

		$content .= '<div class="tml-dashboard-avatar">' . get_avatar( get_current_user_id() ) . '</div>';

		$content .= '<p class="tml-dashboard-greeting">' . sprintf( __( 'Howdy, %s' ), wp_get_current_user()->display_name ) . '</p>';

		/**
		 * Filter the dashboard links.
		 *
		 * @since 7.1
		 *
		 * @param array $links The dashboard links.
		 */
		$links = apply_filters( 'tml_dashboard_links', array_filter( array(
			'site_admin' => current_user_can( 'edit_posts' ) ? array(
				'title'  => __( 'Site Admin' ),
				'url'    => admin_url(),
			) : false,
			'profile'    => array(
				'title'  => __( 'Edit Profile' ),
				'url'    => admin_url( 'profile.php' ),
			),
			'logout'     => array(
				'title'  => __( 'Log Out' ),
				'url'    => wp_logout_url(),
			),
		) ) );

		if ( ! empty( $links ) ) {
			$content .= '<ul class="tml-dashboard-links">';
			foreach ( $links as $link ) {
				$content .= '<li><a href="' . esc_url( $link['url'] ) . '">' . esc_html( $link['title'] ) . '</a></li>';
			}
			$content .= '</ul>';
		}

		$content .= '</div>';
	}

	/**
	 * Filter the shortcode content.
	 *
	 * @since 7.0
	 *
	 * @param string $content The shortcode content.
	 * @param string $action  The action name.
	 * @param array  $atts    The shortcode attributes.
	 */
	return apply_filters( 'tml_shortcode', $content, $action->get_name(), $atts );
}

Code file location:

theme-my-login/theme-my-login/includes/shortcodes.php

Conclusion

Now that you’ve learned how to embed the Theme My Login Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *