How to Add WPForms Shortcodes to PHP Templates

Introduction

Would you like to add your WPForms shortcode directly to your PHP template? There are many different ways to include your WPForms inside your pages an editor from WordPress. You can embed the form inside a post, page, or widget area on your site. However, did you know you can also add a small PHP snippet to have the shortcode run inside any of the PHP templates in your them? In this tutorial, we’ll show you the steps to use to include the shortcode inside a PHP template.

Creating the form

First, you’ll need to create your form and add the fields you wish to have. Our form will have some basic fields to collect our initial contact information for our newsletter.

If you need help in creating your form, please see this documentation.

Adding the shortcode to a PHP template

It’s very important to note that we never recommend making any changes to any of your theme files without the use of a child theme. If you’d like to learn more about creating a child theme, please see this article from our friends at WPBeginner.

For more information on how to add code to any template file in your theme, please review this documentation.

Since we want our newsletter to appear at the bottom of every page on our site automatically, we’re going to use a child theme and edit the footer.php inside our child theme.

Just before the closing content div of the footer, we’re going to add this code.

<?php echo do_shortcode('[wpforms id="25"]');?>

Just be sure to update the id=”25″ with the form ID number you want to include in the template.

Add your WPForms Shortcode to your PHP Template

Now when you load each page of your site, you’ll see the form at the bottom of every page.

adding the shortcode to the footer.php now allows us to display the newsletter form on every page of our site.

And that’s all you need! Would you also like to know how to display a shortcode inside an HTML Field inside your form? Take a look at our article on How to Display Shortcodes Inside the HTML Field.