【问题标题】:Contact Form 7 custom shortcode联系表格 7 自定义简码
【发布时间】:2016-08-06 17:31:33
【问题描述】:

我的 php 经验有点超前。请帮忙。

我正在尝试为联系表单 7 创建自定义简码 - 使用该插件 "developer cook book"

我希望简码获取表单所在页面的 url(永久链接) 然后在返回电子邮件的消息正文中使用这个短代码,或者就是说给企业的电子邮件通知——这样企业就会知道这个表单是从哪个登陆页面提交的,因为这个表单将用于许多登陆页面。

这是我目前的代码,在我的 functions.php 文件中:

add_action('wpcf7_init', 'custom_add_shortcode_lptitle');

function custom_add_shortcode_lptitle() {
    wpcf7_add_shortcode('lptitle', 'custom_lptitle_shortcode_handler'); // "lptitle" is the type of the form-tag
}

function custom_lptitle_shortcode_handler($tag) {
    global $post;
    $url = get_permalink($post->ID);
    return $url;
}

然后我在通知电子邮件的消息正文中使用的短代码是:登陆页面 URL [lptitle]

【问题讨论】:

  • 我本以为更好的方法是获取当前页面 url,并将其注入表单上隐藏字段的值中??

标签: php wordpress shortcode contact-form-7


【解决方案1】:

在您的functions.php 中添加以下代码

wpcf7_add_shortcode('lptitle', 'custom_lptitle_shortcode_handler', true);
function custom_lptitle_shortcode_handler( $tag ) {
    global $post;
    $url = get_permalink($post->ID);
    return $url;
}

你的简码是

[lptitle]

【讨论】:

    猜你喜欢
    • 2012-10-22
    • 2016-09-25
    • 1970-01-01
    • 2014-05-16
    • 1970-01-01
    • 1970-01-01
    • 2019-11-20
    • 2018-12-12
    • 2017-06-23
    相关资源
    最近更新 更多