Email Templates

Updated

You can customise the email template that is used across all of the emails that Content Notify sends out via two methods:

  1. Using a template file.
  2. Using a filter.

The plugin checks for the template file first, then applies the filter. As such, it is possible to override the template file and then override it further using a filter, should you wish. You’ll probably only need to use one of the two methods though.

Using a Template File

To customise the email template that Content Notify uses, copy the wp-content/plugins/content-notify/templates folder to wp-content/themes/your-theme/cn-templates, replacing ‘your-theme’ with the folder name of your theme.

You can then customise the email via this new theme file to include additional information, change the colours and layout, and so on.

This file may be updated with new releases of Content Notify so it’s worth periodically checking that your template version matches that of the main plugin.

Using a Filter

If you prefer to use a filter to override the contents of the email, you can use the filter cn\alert\html.

A full example can be found on the Hooks & Filters page.

PHP Variables

When editing the template, there are a few handy PHP variables that you can use:

Variable Name: $subject
Type: string
Description: This is the subject of the email.

Variable Name: $featured
Type: string
Description: The featured image, pre-formatted as an img tag, if one is set on the post/page/custom post type.

Variable Name: $title
Type: string
Description: This is the title shown at the top of the alert email.

Variable Name: $message
Type: string
Description: The bulk of the alert email, such as the post contents.

Variable Name: $sender_details
Type: array
Description: Contains all data regarding the sender and recipients details for the alert.

Variable Name: $links
Type: array
Description: Contains all links/buttons that show at the bottom of the alert body.

Variable Name: $post
Type: object
Description: Provides access to the $post object so that you can pull in additional information, such as custom field data.

Hide/Show Based on Alert Type

You can conditionally show/hide certain aspects of your email alert by checking against the alert type.
The alert_type is part of the $sender_details PHP variable.

Here are some examples:

Not the verification email (admin and user alerts only)
if ( $sender_details['alert_type'] != 'cn\alert\type\verification' ) {}

Not the admin email (verification and user alerts only)
if ( $sender_details['alert_type'] != 'cn\alert\type\admin' ) {}

Not the user email (verification and admin alerts only)
if ( $sender_details['alert_type'] != 'cn\alert\type\user' ) {}

Only the verification emails
if ( $sender_details['alert_type'] == 'cn\alert\type\verification' ) {}

Only the admin emails
if ( $sender_details['alert_type'] == 'cn\alert\type\admin' ) {}

Only the user emails
if ( $sender_details['alert_type'] == 'cn\alert\type\user' ) {}

Either the admin or the user emails
if ( $sender_details['alert_type'] == 'cn\alert\type\admin' || $sender_details['alert_type'] == 'cn\alert\type\user' ) {}

Get started

Start using it today

Ready to transform your communications for your
visitors, members, subscribers, and users?

View Pricing
14-DAY MONEY BACK GUARANTEE
ON NEW PURCHASES