Enable shortcodes inside the Form Template
Solution 1 - using wpcf7_form_elements
filter
With the wpcf7_form_elements
filter, we can modify the HTML output of the form. Since the output will contain shortcodes that were added in the Form Template, all we need to do is bind do_shortcode
function as a callback to this filter inside functions.php
, like so:
add_filter( 'wpcf7_form_elements', 'do_shortcode' );
Solution 2 - using Contact Form 7 Extension Plugin
If you are uncomfortable with editing functions.php file, there is a plugin available Contact Form 7 Shortcode Enabler that does exactly the same thing.
Note: Currently, the plugin latest update was 5 years ago but the plugin only executes the same line of code as in solution 1, so it should still work with the latest releases of WordPress.
Enable shortcodes inside the Mail Template
The wpcf7_special_mail_tags
filter is used to customize the output of form-tags and special tags of Contact Form 7. Luckily, this filter also detects the custom shortcodes that are found in the Mail Template as well, so we can use this filter to process those shortcodes too.
You need to add the following code inside the functions.php
file:
function my_special_mail_tag( $output, $name, $html ) {
if ( 'myshortcode' == $name )
$output = do_shortcode( "[$name]" );
return $output;
}
add_filter( 'wpcf7_special_mail_tags', 'my_special_mail_tag', 10, 3 );