• Resolved jasnon

    (@jasnon)


    Love the new version so far, great job guys!

    I’m having issues getting custom shortcodes to work within my newsletters. I’ve followed the instructions on this page but it doesn’t seem to be working.

    http://docs.mailpoet.com/article/63-hook-to-add-your-own-shortcode

    Not sure if this method is outdated now in version 3, but if so can you please help explain how to do custom shortcodes in the new version?

    Thanks so much for the support.

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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!

    Plugin Author MailPoet

    (@mailpoet)

    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;

    Done! Thanks again.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Filter Hook for Custom Shortcodes’ is closed to new replies.