Next to dynamic content you can also find your static content in the auto feature of Mailster. To change the output you have to add some custom code to your themes functions.php.

By default the content is either the “excerpt” or the “full content” of your post. You can hook into this data via the “mailster_auto_post” filter.

function my_mailster_auto_post( $data, $post ){

   return $data;
}
add_filter( 'mailster_auto_post', 'my_mailster_auto_post', 10, 2 );

The $data is an array with information to your select post. The $post is a WP_Post object containing the actual post data.

Without changes the $data array contains following information:

$data = array(
   'title' => $post->post_title,
   'alt' => $post->post_title,
   'content' => $content,
   'excerpt' => $excerpt,
   'link' => get_permalink( $post->ID ),
   'image' => array(
        'id' => get_post_thumbnail_id( $post->ID ),
        'name' => $post->post_title,
    ),
 );

If you like to change the title you can do this:

function my_mailster_auto_post( $data, $post ){

   $data['title'] = 'My new Title!';
   return $data;
}
add_filter( 'mailster_auto_post', 'my_mailster_auto_post', 10, 2 );

Targeting multiple elements

By default Mailster uses the first occurrence of a <single> element of the chosen module to inject the $data['title']. If you have multiple <single> elements, <multi> or <img> elements you can return an array like this:

add_filter( 'mailster_auto_post', function ( $data, $post ){

    $data['title'] = array(
            'First Title',
            'Second Title,
    );
    
    return $data;
}, 10, 2 );

This will insert “First Title” into the first <single> element and “Second Title” in the second <single> element.

To change the content of dynamic auto posts check out this article.

Tagged: