Apps Ballance Chat Click Code Cog_Wheels Compose_email Conference Contacts Earth Edit_File_1_ Email Email_2 File Folder_2 Gift Group Group_2 Help ID ID_2 Key Keys Laptop_Store Link Lock Log_Out Map Marketing Mobile_UI Navigation Partnership Profile Safe_2 Search_User Secure_Files Settings Share Shield Shield_2 Shopping_Cart Support_Male Trash Type_pin User_female User_male logo copy

How to create custom email tags

Iain Poulson avatar
Iain Poulson Last updated on March 6, 2021

1. Register your custom tag

To register a new email tag you will need to use the
wpum_email_tags filter. This code can be added to your theme’s functions.php

function wpum_my_email_tag( $tags, $emails ) {

	$tags[] = array(
		'name'        => 'Tag name',
		'description' => 'description goes here',
		'tag'         => 'your_tag',
		'function'    => 'my_email_tag_function'
	);

	return $tags;
}
add_filter( 'wpum_email_tags', 'wpum_my_email_tag', 10, 2 );

In the above example we’ve registered a new tag called “Tag name”, the tag that will then be used within the email is “your_tag”. The function parameter sets the name of the function that will be used to manipulate the output of the tag within the emails. The next step is to create a function with the name specified above.

2. Define the output of the custom tag

The function that handles the output of the tag, takes 1 parameter -> $user_id which can be used to retrieve content related to the user.
In the following example we’re going to retrieve the content of a custom meta field called “wpum_field_11”.
function my_email_tag_function( $user_id ) {

	return get_user_meta( $user_id, 'wpum_field_11', true );

}

3. Add the tag to the emails content

Now that you’re registered the tag and created the output of the tag, you’ll find the new tag within the emails editor. Edit your emails and add {your_tag} to your emails. The tag will now display the content that you defined with your custom function.

Need more help?

If you still didn't find an answer you can always contact us

Submit a ticket