简体   繁体   English

改变联系表格7中[_url]短代码的行为

[英]Change behavior off the [_url] shortcode in contact form 7

I get some dynamic data in the URL that I want to send in my mails. 我在我想要在邮件中发送的URL中获得了一些动态数据。

I use the short code [_url] resulting in this when sending the mails: http://www.example.com/dynamic-content 我在发送邮件时使用了短代码[_url]: http//www.example.com/dynamic-content

I want to remove my domain name and only send the dynamic data when using [_url]. 我想删除我的域名,只在使用[_url]时发送动态数据。

Anyone know how to make a function for this? 有谁知道如何为此功能?

You can add a custom form tag using the wpcf7_form_tag() function. 您可以使用wpcf7_form_tag()函数添加自定义表单标记。

Using that, you can then return whatever data - or make whatever changes to that data - that you like. 使用它,您可以返回您喜欢的任何数据 - 或对数据进行任何更改。

In your theme's functions.php : 在你的主题的functions.php中

add_filter("wpcf7_form_tag", "so_37392974_cf7_url");

function so_37392974_cf7_url($form_tag){
  if($form_tag["name"] == "_custom_url"){
    $form_tag["values"][] = $_SERVER["REQUEST_URI"];
  }
  return $form_tag;
}

When you then add the [_custom_url] tag to your form's e-mail template, it will return something similar to /dynamic-content . 然后,当您将[_custom_url]标记添加到表单的电子邮件模板时,它将返回类似于/dynamic-content

I'm not sure exactly what different forms you are planning on that 'dynamic_content' portion to take, but you can use any PHP function (such as str_replace, substr etc.) to massage the value in the function above before returning it. 我不确定你在'dynamic_content'部分中计划采用哪种不同的形式,但是你可以使用任何PHP函数(例如str_replace,substr等)在返回之前按下上面函数中的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM