Wordpress 如何在联系人表单中显示页面标题?

Wordpress 如何在联系人表单中显示页面标题?,wordpress,contact-form-7,Wordpress,Contact Form 7,我用的是7号联络单。例如,我有一个医生页面,在同一页面上有自己的表单。如何在联系人表单7的输入字段或选择字段中显示该页面的标题 我对联系人表格7的动态数据做了一些研究,我发现了这一点 我将以下代码放入表单中,但它没有检索页面标题: [dynamictext dynamicname “CF7_get_post_var key=’title'”] 非常感谢您的帮助。您尝试过jquery/js吗?类似于jQuery(“#field_id”).val(“”)。您可以在表单使用的页面中尝试此代码。您使用

我用的是7号联络单。例如,我有一个医生页面,在同一页面上有自己的表单。如何在联系人表单7的输入字段或选择字段中显示该页面的标题

我对联系人表格7的动态数据做了一些研究,我发现了这一点

我将以下代码放入表单中,但它没有检索页面标题:

[dynamictext dynamicname “CF7_get_post_var key=’title'”]

非常感谢您的帮助。

您尝试过jquery/js吗?类似于
jQuery(“#field_id”).val(“”)。您可以在表单使用的页面中尝试此代码。

您使用jquery/js尝试过吗?类似于
jQuery(“#field_id”).val(“”)。您可以在表单使用的页面中尝试此代码。

将此代码放到functions.php

add_shortcode( 'cf7_extra_fields', 'cf7_extra_fields_func' );
function cf7_extra_fields_func( $atts ) {
    $html = '';
    $html .= '<input type="hidden" name="page-title" value="<'.get_the_title().'">';
    $html .= '<input type="hidden" name="page-url" value="<'.get_the_permalink().'">';
    return $html;
}
add_shortcode('cf7_extra_fields','cf7_extra_fields_func');
函数cf7_额外_字段_func($atts){
$html='';
$html.='';
$html.='';
返回$html;
}
然后在编辑联系人表单时,在
[cf7\u extra\u fields]中添加此短代码
将表单字段传递到电子邮件时,请使用
[页面标题]
[页面url]

不需要任何插件

将其放入functions.php

add_shortcode( 'cf7_extra_fields', 'cf7_extra_fields_func' );
function cf7_extra_fields_func( $atts ) {
    $html = '';
    $html .= '<input type="hidden" name="page-title" value="<'.get_the_title().'">';
    $html .= '<input type="hidden" name="page-url" value="<'.get_the_permalink().'">';
    return $html;
}
add_shortcode('cf7_extra_fields','cf7_extra_fields_func');
函数cf7_额外_字段_func($atts){
$html='';
$html.='';
$html.='';
返回$html;
}
然后在编辑联系人表单时,在
[cf7\u extra\u fields]中添加此短代码
将表单字段传递到电子邮件时,请使用
[页面标题]
[页面url]

在wpcf7表单中使用短代码不需要插件,一个简单的方法是“Berenis”解决方案,但有一个重要的改变。 而不是
add_shortcode('cf7_extra_fields','cf7_extra_fields_func')应该是
wpcf7\u add\u短代码('cf7\u extra\u fields','cf7\u extra\u fields\u func',true)

剩下的代码可以相同,在functions.php上:

wpcf7_add_shortcode( 'cf7_extra_fields', 'cf7_extra_fields_func', true );
function cf7_extra_fields_func( $atts ) {
   $html = '';
   $html .= '<input type="hidden" name="page-title" value="'.get_the_title().'" />';
   $html .= '<input type="hidden" name="page-url" value="'.get_the_permalink().'" />';
   return $html;
}
wpcf7_add_shortcode('cf7_extra_fields','cf7_extra_fields_func',true);
函数cf7_额外_字段_func($atts){
$html='';
$html.='';
$html.='';
返回$html;
}
在联系人表单中,使用:[cf7\u额外字段],在电子邮件字段中使用:[页面标题]和[页面url]


这对我来说很有效,没有任何问题。

要在wpcf7表单中使用短代码,一个简单的方法是“Berenis”解决方案,但有一个重要的更改。 而不是
add_shortcode('cf7_extra_fields','cf7_extra_fields_func')应该是
wpcf7\u add\u短代码('cf7\u extra\u fields','cf7\u extra\u fields\u func',true)

剩下的代码可以相同,在functions.php上:

wpcf7_add_shortcode( 'cf7_extra_fields', 'cf7_extra_fields_func', true );
function cf7_extra_fields_func( $atts ) {
   $html = '';
   $html .= '<input type="hidden" name="page-title" value="'.get_the_title().'" />';
   $html .= '<input type="hidden" name="page-url" value="'.get_the_permalink().'" />';
   return $html;
}
wpcf7_add_shortcode('cf7_extra_fields','cf7_extra_fields_func',true);
函数cf7_额外_字段_func($atts){
$html='';
$html.='';
$html.='';
返回$html;
}
在联系人表单中,使用:[cf7\u额外字段],在电子邮件字段中使用:[页面标题]和[页面url]


这对我来说很有效,没有任何问题。

晚了一年,但我只是看到了它。我想你已经解决了。错误是因为短代码的字符错误。正确的做法是这样的:

[dynamictext dynamicname "CF7_get_post_var key='title'"]

问候

晚了一年,但我刚刚看到了。我想你已经解决了。错误是因为短代码的字符错误。正确的做法是这样的:

[dynamictext dynamicname "CF7_get_post_var key='title'"]

问候

有没有办法只在联系方式7或CMS的内部页面中使用,而不必编辑后端?因为将会有超过10个不同格式的页面。你尝试过的插件提供了这样的选项,请阅读它的描述。CF7\u get\u post\u var key='title'是否有一种方法只在联系人表单7或CMS的内部页面中使用,而不必编辑后端?因为将会有超过10个不同格式的页面。你尝试过的插件提供了这样的选项,请阅读它的描述。CF7\u get\u post\u var key='title'试试这个试试这个