Add a Gravity Forms shortcode in WordPress (PHP)

To add a Gravity Form shortcode in the header, page, footer templates… pretty much anywhere in the theme, just add this code in your PHP file:

<?php echo do_shortcode('[gravityf0rm id=1 name=ContactUs title=false description=false]'); ?>

You can also add the embed codes:

Basic
<?php gravity_form( 1, false, false, false, '', false ); ?>

This snippet will display the form with an id of ‘1’; the title and description will not be displayed, the form itself will not display if it is inactive, and it will not use AJAX for form submission.

With Ajax & Tabindex

<?php gravity_form(1, false, false, false, '', true, 12); ?>

This snippet will display the exact same form as above except it will use AJAX for form submission and the starting tabindex will be 12.

Using the Form Title instead of ID

<?php gravity_form('Contact Us', false, false, false, '', false); ?>

This snippet will display the form titled ‘Contact Us’; the title and description will not be displayed, the form itself will not display if it is inactive, and it will not use AJAX for form submission.

What is Gravity Forms?

Gravity Forms is a contact form plugin that seamlessly integrates into WordPress.org CMS (content management system). The popularity stems from its turnkey setup, bulletproof functionality, and the assortment of available add-ons.

Alternative Gravity Forms uses:

Besides a basic contact form:

  1. Guest Posts

    Guest Posts is a quick way for bloggers to build quality backlinks. Using Gravity Forms it is possible to automate the process, allowing the poster to select the Title, Body, Excerpt, Tags, Categories, Featured Image, + any Custom Fields you might have.

  2. Surveys, Polls, and Templates

    Gravity forms are great for surveys and polls; there is even an add-on that makes the functionality more robust. Using Gravity Forms conditional logic, you can change how the form operates depending on the answers provided.

    To give you an example of this, if you have a multiple choice question, and none of the answers apply, you can have a single line box pop up under the multiple choice question, asking for additional information.

    If you have specific templates, Gravity Forms can be used to aid in filling them out. With Gravity Forms, you can set minimum, and maximum character counts, required fields, and additional information.

  3. Support Forms

    Gravity Forms supports file uploads, specific notifications based on the request, and hidden fields to track IP address and referral pages, all which makes it perfect for a support functionality.

Isaac Adams-Hands

Full Stack Developer, Digital Marketer, and InfoSec enthusiast. He received his Bachelor’s Degree from the University of Western Sydney and his Business Diploma from Georgian College before joining various marketing positions in search portals, e-commerce, higher education, and addiction recovery services.

Follow @ twitter

Related posts

How to hide Gravity Form field labels

If you want to add support to hide field labels on a field by field basis, simply add the following line of code to your themes (functions.php). Make sure to remove the opening and closing php tags add_filter( ‘gform_enable_field_label_visibility_settings’, ‘__return_true’ ); What this code does is adds a Field Label Visibility dropdown under the Appearance… Read More

Dynamic Page Listings in #WP

Here is how-to dynamically list all children pages associated under a parent page in WordPress. This allows you to change and update pages without updating a sidebar widget/page, and removes the need to create numerous distinct sidebars/sections. To enable this code, add it to your WordPress themes functions.php file, then add the shortcode to the… Read More