Wordpress Contact form 7 custom shortcodes

Question :
Contact form 7 has some shortcodes, like [_date] to get todays date. But I want to display the date one week from now.
So I need to create a custom shortcode to Contact form 7 that takes say [next_week] and in the received email the correct date is displayed.
Where and how do I create custom shortcodes to Contact form 7?
Solution code for : Wordpress Contact form 7 custom shortcodes
Adding the following to your functions.php
wpcf7_add_shortcode('custom_date', 'wpcf7_custom_date_shortcode_handler', true);

function wpcf7_custom_date_shortcode_handler($tag) {
    if (!is_array($tag)) return '';

    $name = $tag['name'];
    if (empty($name)) return '';

    $next_week = date('Y-m-d', time() + (60*60*24*7)); 
    $html = '';
    return $html;
}
Now in the "Form" field in CF7 GUI type [custom_date next_week]
Now you can use [next_week] in the message body.

No comments:

Post a Comment