Additional HTML templates

To add additional HTML templates, plugin includes a simple method for registering new templates you want to use. This tutorial shows the potential implementation method, but you can use different approaches too.

Storing templates files

When you create your HTML template, it is highly recommended to have all the CSS in the HTML file, and not to link CSS files from a web server, because most email clients will not allow loading of external CSS. You can store your templates somewhere inside the wp-content folder for WordPress, and for this tutorial I recommend adding a new directory called ‘mail-templates‘ inside the ‘wp-content/uploads‘ directory. Now, place your new HTML template file into the ‘wp-content/uploads/mail-templates‘ directory.

  • Make sure that your HTML template is valid for emails, and you can use the templates included with the plugin as a starting point. There are many tutorials online and many finished templates and template boilerplates for HTML emails that are valid in a wide range of email clients.
  • Give the templates file simple names. Some file names can cause problems on Linux web servers, so make sure to use lowercase letters only, don’t use spaces, and instead use dashes and underscores.
  • Name of the template should use .htm or .html extensions.

For this tutorial, let’s say you created two templates: ‘custom-test.html‘ and ‘custom-advanced.html‘.

Register templates with the plugin

The plugin requires additional templates to be registered, so that plugin can find and use the templates. The proposed way to do this is to add ‘must use plugin‘ (mu-plugin). Before you do that, check to see if your website installation has a mu-plugins directory inside the wp-content directory. If there is no such directory, make it. WordPress loads all PHP files inside this directory before it loads any other plugin. Now, inside this directory add empty file: ‘mail-queue-templates.php‘. Path to this file would be ‘wp-content/mu-plugins/mail-queue-templates.php‘.

Finally, open that file for editing and add this code inside:


add_action('gdmaq_register_templates', 'custom__gdmaq_templates');

function custom__gdmaq_templates() {
    $dir = WP_CONTENT_DIR.'/uploads/mail-templates/';

    gdmaq()->register_template('custom-test', 'Custom Test', $dir.'custom-test.html');
    gdmaq()->register_template('custom-advanced', 'Custom Advanced', $dir.'custom-advanced.html');

Line 3 hooks the new function to the plugin action for templates registration. Lines 5 through 10 are the function for registration of new templates. Line 6 defines the path to our directory with templates. Line 8 and 9 register individual templates.

Old plugin versions

Plugin version before 5.0 Pro and 3.5 Lite had the option of setting a custom HTML template from the plugin interface. This has been removed now. On one hand, we have the need for a complex HTML for an email with quirky tags and attributes, and on the other hand, we have the need for security and for properly sanitized input, including this HTML. There is no way in WordPress to properly sanitize such a complex HTML without losing things, so the only way to allow HTML email in full, is to skip sanitation and open potential security hole, and that is not a good option.

Rate this article

You are not allowed to rate this post.

Leave a Comment