• Resolved dillhausen

    (@dillhausen)


    Hi,

    I would like to use different text strings in my newsletter depending on the total count of posts in the newsletter, i.e. the number that is available in shortcode [newsletter:total].

    I have read about creating custom short codes here, and I think this might be the solution. According to this documentation, I have successfully created my own shortcode [custom:subheader] and used it in the email editor. But in order to make it work, I need the php code to assign the value for the total number of posts to my internal varable $count.

    Can you please help me with this?

    Thank you

    So far, my code looks like this, the point where I need help is marked “PLEASE HELP ME HERE”:

    add_filter('mailpoet_newsletter_shortcode', 'mailpoet_kahi_shortcode', 10, 6);

    function mailpoet_kahi_shortcode($shortcode, $newsletter, $subscriber, $queue, $newsletter_body, $arguments)
    {
    // always return the shortcode if it doesn't match your own!
    if ($shortcode !== '[custom:subheader]') return $shortcode;

    $count = 0;
    $subheader = "Dies ist eine automatische Benachrichtigung über ";
    $count == PLEASE HELP ME HERE

    if ($count !== 1)
    {
    $subheader .= $count;
    $subheader .= " neue ";
    }
    else
    {
    $subheader .= "einen neuen ";
    }
    $subheader .= "Artikel ";

    return $subheader;
    }

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Support Ojoma a11n

    (@geraltrivia)

    Hello there @dillhausen ,

    Thanks for reaching out and for taking the time to explain what you’re trying to achieve. I can see you’ve already done quite a bit of research and experimentation here, and it makes sense why you’d want to adjust the newsletter text based on the number of posts included.

    At the moment, this kind of dynamic logic is not something MailPoet supports out of the box. While MailPoet does provide shortcodes and filters, using them to access internal values like the total number of posts in a newsletter and then conditionally change content would require custom PHP code.

    I do want to be upfront that we’re not able to provide support for writing or debugging custom code like this. Anything that involves custom shortcodes, internal variables, or custom PHP logic falls outside our scope of support.

    That said, if you’d like hands on help implementing or validating a custom solution, we recommend working with a MailPoet certified developer via Codeable. They’re familiar with MailPoet internals and can help you build and maintain a solution safely:

    https://www.codeable.io/partners/mailpoet/

    If you have any questions about what MailPoet can do natively, feel free to let me know and I’ll be happy to help with that.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.