[英]Contact Form 7 custom placeholder text
I have a contact form on every post. 我在每个职位上都有联系表格。 I am trying to display a different placeholder text on subject field on every post, where subject field placeholder text should be equal to the post title.
我正在尝试在每个帖子的主题字段上显示不同的占位符文本,其中主题字段占位符文本应等于帖子标题。
So this is current contact form tag: 这是当前的联系表单标签:
[text text-900 placeholder "Subject"]
I tried replacing Subject with 我试着更换与主题
<script>
$("input").val("<?php echo $post; ?>");
</script>
but it hasn't worked. 但是没有用。
Please help me solve this problem :) 请帮我解决这个问题:)
Try this 尝试这个
jQuery('.wpcf7-form input[type=text]').attr("placeholder", "Your Post Title")
Complete PHP Code is below. 完整的PHP代码如下。 Tested.
测试。
<script type="text/javascript">
jQuery('.wpcf7-form input[type=text]').attr("placeholder", "<?php the_title(); ?>");
</script>
First add the class like this as per the docs of contact-form 7 首先按照contact-form 7的文档添加这样的类
[text class:subject_form text-900 placeholder "Subject"]
then on somewhere at top of your .php file initilalize the global variable of title 然后在.php文件顶部的某个地方初始化title的全局变量
<script>
page_title = "<?php echo the_title()?>";
</script>
then 然后
in jQuery 在jQuery中
<script>
jQuery('.wpcf7-form input.subject_form').attr("placeholder", page_title);
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.