You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在VS Code中编写Contact Form 7表单短代码

How to Add Your Contact Form 7 Shortcode in VS Code

Hey there! Adding that Contact Form 7 shortcode in VS Code is totally straightforward—here's exactly how to do it, depending on what file you're editing:

1. Open the correct file in VS Code

First, open the file where you want the contact form to appear. For WordPress sites, this is usually a template file like page.php, single.php, a custom template (e.g., template-contact.php), or even a custom block/widget file if you’re building components.

2. Insert the shortcode properly

For PHP files (WordPress templates):

WordPress doesn’t parse raw shortcodes directly in PHP files, so you need to wrap your shortcode in the do_shortcode() function to make it render. Paste this line exactly where you want the form to show up:

<?php echo do_shortcode('[contact-form-7 id="2722" title="Contact form 1"]'); ?>

Double-check that the id and title values match exactly what’s listed in your WordPress admin’s Contact Form 7 settings—typos here will break the form.

For content files (HTML, Markdown, or WordPress post content):

If you’re working in a file that’s processed for shortcodes (like a post’s content saved as HTML, or a static site generator that supports shortcode parsing), you can paste the shortcode directly without any extra code:

[contact-form-7 id="2722" title="Contact form 1"]

3. Save and test

Save your changes in VS Code (Ctrl+S on Windows/Linux, Cmd+S on Mac). If you’re editing remote files, use an FTP/SFTP extension (like VS Code’s built-in SFTP support or extensions like FTP Sync) to upload the updated file to your server. Then preview your site—if the form doesn’t load, make sure:

  • The Contact Form 7 plugin is active on your WordPress site
  • The shortcode ID matches the one in your CF7 dashboard
  • You used the correct syntax for your file type (PHP vs content)

Quick pro tip: If you work with WordPress in VS Code often, install extensions like WordPress Snippets or PHP Intelephense—they’ll give you syntax highlighting and auto-completion for WordPress functions like do_shortcode(), which saves time and reduces typos.

内容的提问来源于stack exchange,提问作者unknownuserpprofile

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 20:17:43