Thank you for the feedback!
We’ve yet to update our documentation. In the meantime, here is how you would add a custom shortcode (e.g., [custom:shortcode]) to your newsletter:
add_filter('mailpoet_newsletter_shortcode', 'custom_shortcode', 10, 5);
function custom_shortcode($shortcode, $newsletter, $subscriber, $queue, $newsletter_body) {
if ($shortcode === '[your:shortcode]') {
return "some content";
}
}
If you’re adding a link shortcode, make sure that it starts with [link:...] and then use the following code:
add_filter('mailpoet_newsletter_shortcode_link', 'custom_shortcode', 10, 4);
function custom_link($shortcode, $newsletter, $subscriber, $queue) {
if ($shortcode === '[link:some_link]') {
return "http://example.com";
}
}
We hope this helps!
-
This reply was modified 9 years, 6 months ago by
Wysija.
-
This reply was modified 9 years, 6 months ago by
Wysija.
Thread Starter
jasnon
(@jasnon)
Worked perfect thanks so much for the quick response!
Looking at the MailPoet code, I believe to avoid conflicts with other plugins, the example code should return $shortcode if its not a match? ie.
add_filter( 'mailpoet_newsletter_shortcode', 'custom_shortcode', 10, 5 );
function custom_shortcode( $shortcode, $newsletter, $subscriber, $queue, $newsletter_body ) {
if ($shortcode === '[your:shortcode]') {
return "some content";
}
return $shortcode;
}
Otherwise the second call to that filter will have $shortcode as null and never match.
@brianhogg good catch, thank you!
The updated KB article: http://beta.docs.mailpoet.com/article/160-create-your-own-custom-shortcode
-
This reply was modified 9 years, 5 months ago by
Wysija.
No problem!
The second link code example may also need return $shotcode; vs just return;