1. Home
  2. Advanced
  3. Using hooks to customise email content

Using hooks to customise email content

Newsletter Glue offers 2 hooks that give you access to customize the content of email. They only work in the email context (so the regular post content will not be affected)

The hooks are:

$the_content = apply_filters( 'newsletterglue_email_content_header', $the_content, $app, $post );
$the_content = apply_filters( 'newsletterglue_email_content_footer', $the_content, $app, $post );

The first parameter is the email content, much like the_content filter. Second parameter passed the $app (Which is current ESP – e.g. mailchimp, mailerlite) and Last parameter passed the $post object. Here is a very quick usage example.

function newsletter_top( $content, $app, $post ) {

    $content .= 'HEADER';

    return $content;
}
add_filter( 'newsletterglue_email_content_header', 'newsletter_top', 10, 3 );

function newsletter_bottom( $content, $app, $post ) {

    $content .= 'FOOTER';

    return $content;
}
add_filter( 'newsletterglue_email_content_footer', 'newsletter_bottom', 10, 3 );

That would insert very simple words, but ofcourse you can put any custom content there.
Important note: For email compatibility and ensuring that your custom content will be rendered correctly across various clients, please use tables markup to add custom content.

Example:

<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td>My custom content here</td></tr></table>

These hooks do not run in the blog post content (Only in email/email preview)

You can also target content for a specific ESP. By using conditional logic combined with $app to check if the email is processed to Mailchimp for example, and add specific content only if the ESP matches.

function newsletter_bottom( $content, $app, $post ) {

if ( $app === 'mailchimp' ) {
    $content .= 'I am sending this to Mailchimp only!!';
}
    return $content;
}
add_filter( 'newsletterglue_email_content_footer', 'newsletter_bottom', 10, 3 );
Updated on May 5, 2023

Was this article helpful?

Get more help
Can't find the answer you're looking for? Get in touch.
Contact support