auto featureIf you regularly include dynamic posts in your campaigns you are familiar with the auto feature of Mailster. To change the content of this feature you can add a simple function in your themes function.php file.

By default the content used in this feature looks like this:



This will insert the title of your last post ({post_title:-1}) as headline and the excerpt ({post_excerpt:-1}) as content. In the editbar it will look something to this:

editbar and dynamic tags

If you like to link the headline to the actual blog post you can wrap the anchor tag around the tag. Add a new snippet to your themes functions.php:

function my_mailster_auto_tag( $pattern, $post_type, $options, $post ){

	return $pattern;
add_filter( 'mailster_auto_tag', 'my_mailster_auto_tag', 10, 4 )

This will basically adds a filter to the ‘mailster_auto_tag’ and allows you to alter the $pattern of your output. At this state it returns the original $pattern so there’s actually no change.

Changing the pattern

The $pattern is an associative array and contains following keys:

  • title – the string used for the title
  • alt – used for the alt tag if an image is in the module
  • content – used if content is selected
  • excerpt – used if excerpt is selected
  • link – the link to the post
  • image – the image tag which links to the feature image of the post

To wrap wrap the title with a link you have to add one line to your function:

$pattern['title'] = '<a href="{'.$post_type.'_link:'.$options.'}">{'.$post_type.'_title:'.$options.'}</a>

This replaces the old title and add a new pattern with links. Note the $post_type variable which gets replaced with the selected post type. The $options represents the content after the “:” which is -1 for the latest post in this case.

Adding the name of the author

You can append the authors name after the excerpt if you add this line:

$pattern['excerpt'] .= "<br>".'by {'.$post_type.'_author_name:'.$options.'}';

The whole code snippet you have to add looks like this:

function my_mailster_auto_tag( $pattern, $post_type, $options, $post ){

    $pattern['title'] = '<a href="{'.$post_type.'_link:'.$options.'}">{'.$post_type.'_title:'.$options.'}</a>';
    $pattern['excerpt'] .= "<br>".'by {'.$post_type.'_author_name:'.$options.'}';
    return $pattern;

add_filter( 'mailster_auto_tag', 'my_mailster_auto_tag', 10, 4 );

The editbar now reflects your changes and you will know if everything went well. editbar with custom auto tags

Did you know you can exclude certain posts from Mailster? Read more.