Adding a Contact Form 7 form into a PHP template in WordPress

Sometimes you may want to add a contact form 7 form into a template directly. While normal use is via a shortcode eg,

[contact-form-7 id="200" title="My Contact Form"]

you can’t use this directly inside a PHP page template.

Instead, you need to wrap this inside the WordPress do_shortcode function, in order to enable it to parse correctly. Wrapping your form up like this will render it correctly in the page using this template:

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

And voila, you have a CF7 form embedded from inside a PHP page template.

Useful post? Share it

Leave a Reply

Your email address will not be published.