You can customise the default alert email template that is used for the emails that are sent immediately that Content Notify sends out via two methods:
- Using a template file.
- 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.
The digest alert template can only be overridden using the template file method, mentioned below.
Using a Template File #
To customise the email templates that Content Notify uses for immediate and digest alerts, 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.
For quick reference, the $sender_details['subscription_details']
array item contains details of the subscription itself, such as the post type, status, terms, keywords, etc. chosen at the time.
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.
Variable Name: $entry
Type: array
Description: Provides access to the subscriber’s details that relate to the alert being sent.
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 emailsif ( $sender_details['alert_type'] == 'cn\alert\type\verification' ) {}
Only the admin emailsif ( $sender_details['alert_type'] == 'cn\alert\type\admin' ) {}
Only the user emailsif ( $sender_details['alert_type'] == 'cn\alert\type\user' ) {}
Either the admin or the user emailsif ( $sender_details['alert_type'] == 'cn\alert\type\admin' || $sender_details['alert_type'] == 'cn\alert\type\user' ) {}