Viewing 6 replies - 1 through 6 (of 6 total)
  • add a name attribute on the form element and make your mail section shortcode out of it.

    Example:​​

    <li name="custom_name"> some list </li>

    in the mail section/message you will use [custom_name] as your shortcode​​​ to display input from the

    <li> field in your email.</li>

    Thread Starter maestro2012

    (@maestro2012)

    I mean, to shortcode, like this:

    // [foobar]
    foobar_func function ($ atts) {
    return "foo and bar";
    }
    add_shortcode ('foobar', 'foobar_func');

    So that was attached to the message content “foo and bar”.

    Try this: Custom shortcode in emails.

    @mods: A not closed <li> close to the end of above post of davmerit seems to kill the layout..

    Tim Nash

    (@tnash)

    Spam hunter

    Layout Fixed 🙂 Folks remember to always encapsulate your code with backticks or use the code button.

    Thanks

    Thread Starter maestro2012

    (@maestro2012)

    Ov3rfly, thank you for link, this is working.

    add_filter( 'wpcf7_special_mail_tags', 'foobar_func', 10, 3 );
    //[foobar]
    function foobar_func( $atts ){
    	return "foo and bar";
    }
    add_shortcode( 'foobar', 'foobar_func' );

    insert [foobar] to Message Body.

    This might work for this one case but it is just wrong, it does return the same output for every possible special mail tag.

    Here is a correct version based on the linked code example:

    add_filter( 'wpcf7_special_mail_tags', 'your_special_mail_tag', 10, 3 );
    
    function your_special_mail_tag( $output, $name, $html ) {
    	if ( 'foobar' == $name )
    		$output = do_shortcode( '[foobar]' );
    
    	return $output;
    }
    
    // [foobar]
    function foobar_func( $atts) {
    	return "foo and bar";
    }
    add_shortcode ('foobar', 'foobar_func');

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

The topic ‘custom shordcode in message’ is closed to new replies.