admin管理员组

文章数量:1129441

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 11 months ago.

Improve this question

I have added the short-code in my Contact Form 7 Message Body but it is not working.

function.php

function wpb_demo_shortcode() { 

 $output = '<p style="font-size:11pt;font-family:Calibri,sans-serif;margin:0;">Lets stay connected!</p>';

 return $output;
 } 
 // register shortcode
 add_shortcode('greeting', 'wpb_demo_shortcode');

/**
 * A tag to be used in "Mail" section so the user receives the special tag
 * [greeting]
 */
add_filter('wpcf7_special_mail_tags', 'wpcf7_tag_tournament', 10, 3);
function wpcf7_tag_tournament($output, $name, $html)
{
    $name = preg_replace('/^wpcf7\./', '_', $name); // for back-compat

    $submission = WPCF7_Submission::get_instance();

    if (! $submission) {
        return $output;
    }

    if ('greeting' == $name) {
        return $submission->get_posted_data("greeting");
    }

    return $output;
}

// Other Code 
add_filter( 'wpcf7_form_elements', 'mycustom_wpcf7_form_elements' );

function mycustom_wpcf7_form_elements( $form ) {
$form = do_shortcode( $form );

return $form;
} 

I have added this code in my functions.php but my shortcode is not showing html in the email.

Added this in the Message Body: [greeting]

Any help is much appreciated.

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 11 months ago.

Improve this question

I have added the short-code in my Contact Form 7 Message Body but it is not working.

function.php

function wpb_demo_shortcode() { 

 $output = '<p style="font-size:11pt;font-family:Calibri,sans-serif;margin:0;">Lets stay connected!</p>';

 return $output;
 } 
 // register shortcode
 add_shortcode('greeting', 'wpb_demo_shortcode');

/**
 * A tag to be used in "Mail" section so the user receives the special tag
 * [greeting]
 */
add_filter('wpcf7_special_mail_tags', 'wpcf7_tag_tournament', 10, 3);
function wpcf7_tag_tournament($output, $name, $html)
{
    $name = preg_replace('/^wpcf7\./', '_', $name); // for back-compat

    $submission = WPCF7_Submission::get_instance();

    if (! $submission) {
        return $output;
    }

    if ('greeting' == $name) {
        return $submission->get_posted_data("greeting");
    }

    return $output;
}

// Other Code 
add_filter( 'wpcf7_form_elements', 'mycustom_wpcf7_form_elements' );

function mycustom_wpcf7_form_elements( $form ) {
$form = do_shortcode( $form );

return $form;
} 

I have added this code in my functions.php but my shortcode is not showing html in the email.

Added this in the Message Body: [greeting]

Any help is much appreciated.

Share Improve this question asked Feb 26, 2020 at 14:49 Rahul KumarRahul Kumar 2074 silver badges20 bronze badges 2
  • Shortcodes are only parsed in post content. You could try echo do_shortcode('[greeting]') to try to force WP to parse it. – WebElaine Commented Feb 26, 2020 at 15:17
  • @WebElaine. In the message body or in the functions.php? – Rahul Kumar Commented Feb 26, 2020 at 18:03
Add a comment  | 

1 Answer 1

Reset to default 2

You can place only the following code in functions.php and it will work:

// Activate Shortcode Execution for Contact Form 7

add_filter( 'wpcf7_form_elements', 'do_shortcode' );

本文标签: My shortcode is not working in Contact Form 7 Message Body