• Resolved vi54

    (@vi54)


    Hi there.

    I have a very simple shortcode to display our latest offer. The shortcode expands perfectly on a widget, post, anywhere in WordPress.

    However when using the shortcode in the email sending after the opt-in, I can see the code aka [MYCODE] instead of the returned value.

    How to ensure custom shortcodes are expanded in emails?

    As a secondary question: Is there a hook to listen to when an email will be sent?
    So I can trigger a custom function?

    I am willing to create a new topic when required.

    Thanks for your expertise.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Laura – WPMU DEV Support

    (@wpmudev-support8)

    Hi @vi54

    I hope you’re well today!

    For shortcode to be “expanded” in e-mail content it would have to be processed first on your site’s end, before the e-mail is being send. Hustle does not execute shortocodes in that e-mail message by default, mostly for compatibility and security reasons and currently changing that would require more changes directly in plugin’s core (as there’s no hooks built-in that we could use).

    A workaround could be to try code to hook to default wp_mail() function (that is used by Hustle too), like this:

    add_filter( 'wp_mail','shortcode_in_mail', 10 ,1 );
    function shortcode_in_mail( $args ) {
        
    	if ( strstr( $args['message'], '[MYCODE]' ) ) {
    	
    		$args['message'] = do_shortcode( $args['message'] );
    	
    	}
    	
        return $args;
    	
      }

    You would need to add that to functions.php of your current (child) theme and replace the

    [MYCODE]

    with your real shortcode (this is for security, so no other shortcodes would be executed in other e-mail – as this code would not only be applied to Hustle but to all e-mails sent from your site).

    Best regards,
    Adam

    Thread Starter vi54

    (@vi54)

    High Five! Awesome!

    Thank you so much!

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

The topic ‘Shortcode not expanding in email’ is closed to new replies.