Using hooks to customise email content

Avatar

By Ahmed Fouad

updated 14 days ago

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 );

Did this answer your question?