WordPress的联系方式7自定义短代码 [英] Wordpress Contact form 7 custom shortcodes

查看:92
本文介绍了WordPress的联系方式7自定义短代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

联系表7包含一些短代码,例如[_date]以获取今天的日期。但是我想显示从现在开始一周的日期。

Contact form 7 has some shortcodes, like [_date] to get todays date. But I want to display the date one week from now.

因此,我需要为自定义联系表7创建一个自定义的简码,其内容为[next_week],并在收到的电子邮件中

So I need to create a custom shortcode to Contact form 7 that takes say [next_week] and in the recived email the correct date is displayed.

我在哪里以及如何为联系表单7创建自定义简码?

Where and how do I create custom shortcodes to Contact form 7?

推荐答案

将以下内容添加到您的函数中。php

Add 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 = '<input type="hidden" name="' . $name . '" value="' . $next_week . '" />';
    return $html;
}

现在在CF7 GUI的表单字段中键入 [custom_date next_week]

Now in the "Form" field in CF7 GUI type [custom_date next_week]

现在您可以在消息中使用 [next_week] 身体。

Now you can use [next_week] in the message body.

这篇关于WordPress的联系方式7自定义短代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆