N
N
Newn2018-03-20 14:40:42
WordPress
Newn, 2018-03-20 14:40:42

How to add custom shortcode to contact form 7 plugin email template?

I created my own short code for cf7 and you paste it into the form and it works, but it does not work if you add email to the template. How to implement this feature? Has anyone done this before? Almost no information found. Just a mention that you put a filter. But even then it is not clear how to work with him.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Newn, 2018-03-20
@Newn

Here is a code example to help you.

add_filter( 'wpcf7_form_elements', 'do_shortcode' );

function hello_world_cf7_func() {
   return "Привет! Я шоркод для Contact Form 7!";
}
add_shortcode('hello_world', 'hello_world_cf7_func');
//----------------------------------------------------------------

add_filter('wpcf7_mail_components', 'do_shortcode_mail', 10, 3);
function do_shortcode_mail( $components, $contactForm, $mailComponent ){
  if( isset($components['body']) ){
    $components['body'] = do_shortcode($components['body']);
  }

  return $components;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question