Wordpress联系表格7个自定义短代码

hal*_*uud 12 wordpress contact-form-7 shortcode

联系表格7有一些短代码,比如[_date]来获取今天的日期.但我想在一周后显示日期.

因此,我需要为联系表单7创建一个自定义短代码,其中显示[next_week],并在收到的电子邮件中显示正确的日期.

我在何处以及如何创建自定义短代码以联系表单7?

hal*_*uud 19

将以下内容添加到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 = '<input type="hidden" name="' . $name . '" value="' . $next_week . '" />';
    return $html;
}
Run Code Online (Sandbox Code Playgroud)

现在在CF7 GUI类型的"Form"字段中 [custom_date next_week]

现在您可以[next_week]在邮件正文中使用.

  • 我可以根据需要使用一个更简单的版本:`wpcf7_add_shortcode('input_name',function($ tag){return'&lt;输入名称=“'。$ tag ['basetype']。'” value =“ your_value” /&gt;''} );` (2认同)