Title: question about custom short code
Last modified: December 11, 2025

---

# question about custom short code

 *  Resolved [dillhausen](https://wordpress.org/support/users/dillhausen/)
 * (@dillhausen)
 * [6 months ago](https://wordpress.org/support/topic/question-about-custom-short-code/)
 * 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](https://kb.mailpoet.com/article/160-create-a-custom-shortcode),
   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”:
 *     ```wp-block-code
       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](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fquestion-about-custom-short-code%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Support [Ojoma a11n](https://wordpress.org/support/users/geraltrivia/)
 * (@geraltrivia)
 * [5 months, 3 weeks ago](https://wordpress.org/support/topic/question-about-custom-short-code/#post-18757534)
 * Hello there [@dillhausen](https://wordpress.org/support/users/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/](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](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fquestion-about-custom-short-code%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/mailpoet/assets/icon-256x256.png?rev=3284564)
 * [MailPoet - Newsletters, Email Marketing, and Automation](https://wordpress.org/plugins/mailpoet/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/mailpoet/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/mailpoet/)
 * [Active Topics](https://wordpress.org/support/plugin/mailpoet/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/mailpoet/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/mailpoet/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Ojoma a11n](https://wordpress.org/support/users/geraltrivia/)
 * Last activity: [5 months, 3 weeks ago](https://wordpress.org/support/topic/question-about-custom-short-code/#post-18757534)
 * Status: resolved