好吧,我可能误解了你想要什么,但是:
这是 CF7 注册文本字段短标签的方式:
add_action( 'wpcf7_init', 'wpcf7_add_shortcode_text' );
function wpcf7_add_shortcode_text() {
wpcf7_add_shortcode(
array( 'text', 'text*', 'email', 'email*', 'url', 'url*', 'tel', 'tel*' ),
'wpcf7_text_shortcode_handler', true );
}
请注意,函数 wpcf7_add_shortcode() 的钩子是 wpcf7_init 所以,如果我们自己做例子:
add_action( 'wpcf7_init', 'custom_add_shortcode_hello' );
function custom_add_shortcode_hello() {
wpcf7_add_shortcode( 'helloworld', 'custom_hello_shortcode_handler' ); // "helloworld" is the type of the form-tag
}
然后是回调处理程序
function custom_hello_shortcode_handler( $tag ) {
return 'hello world ! ';
}
现在,如果您将其添加到表单中
CF7 say : [helloworld]
你应该看到
CF7 say : hello world !
如果你想使用普通的表单标签,请注意可用的默认类型是:
text, text*, email, email*, tel, tel*, url, url*, textarea ,textarea* , number, number*, range and range* , date , date*,checkbox, checkbox*, radio, select and select* , file , file*, captchac ,captchar, quiz , acceptance, submit;
现在,我写了所有这些,因为据我所知(而且我可能错了)对于在函数 wpcf7_tg_pane_text_and_relatives() in modules/text.php 中定义的现有标签的 HTML 表单没有过滤器/p>
,但是您可以做的是使用 wpcf7_remove_shortcode( $tag ); 删除默认标签(例如 text ),然后通过创建一个新标签(例如 text )添加您自己的适应上面的示例以适应您的需要
话虽如此,我还不确定你想要什么以及为什么想要这个(你真的没有解释目标,只是方式)因为恕我直言,并且在我编写了很多 CF7 自定义插件之后,我真的想要不明白为什么不直接创建一个新标签,这样更容易构建。
但话说回来,我可能错了。