Filter hook to add your own shortcode

This article refers to MailPoet 2

If you're looking for MailPoet 3 articles, please go to MailPoet 3 Knowledge Base

Developers who wish to extend the MailPoet shortcodes (display subscriber's first name, last name, date, year, etc.) for their own usage can do so by extending this example to their theme's functions.php file.

These shortcodes will render in:

  • the body of your newsletters
  • the subject line
  • the confirmation email (in your Settings)

For example, you could display a list of products from WooCommerce. Or a table of custom contents.

Otherwise, view the list of default shortcodes.

 * This is an example of a custom shortcode parser.
 * It's really easy to implement.
 * We already automatically parse all shortcodes with this notation for you: [custom:my_value]
 * You just have to add a filter and return the value you prefer.
 * In the following example we added [custom:my_name] and [custom:blog_name] to our newsletter.
 * We have now to return the preferred values, as string.
// [custom:my_name]
// [custom:blog_name]
function mailpoet_shortcodes_custom_filter( $tag_value , $user_id) {
    // $tag_value contains the string after custom:
    // This function will be called the first time with $tag_value = my_name
    // The second time with $tag_value = blog_name
    // $user_id contains the corresponding MailPoet's subscriber id,
    // this could be useful to fetch extra data from the WordPress user's meta for instance
    // e.g.:

    if ($tag_value === 'my_name') {
        $replacement = 'Maily';

   if ($tag_value === 'blog_name') {
        $replacement = get_bloginfo('name');
    return $replacement;
add_filter('wysija_shortcodes', 'mailpoet_shortcodes_custom_filter',10 ,2);