WPForms Shortcode

Below, you’ll find a detailed guide on how to add the WPForms Lite Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the WPForms Lite Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the WPForms Lite Plugin and the shortcodes it provides:

Plugin Icon
Contact Form by WPForms – Drag & Drop Form Builder for WordPress

"Contact Form by WPForms is a user-friendly WordPress plugin. This drag & drop form builder allows you to create fantastic forms in no time. Use WPForms Lite for easy, efficient form creation."

★★★★☆ (13392) Active Installs: 5000000+ Tested with: 6.3.2 PHP Version: 7.0
Included Shortcodes:
  • [wpforms]

WPForms Lite [wpforms] Shortcode

The WPForms Lite plugin shortcode is a powerful tool designed to display forms on your WordPress site. This shortcode utilizes the ‘id’, ‘title’, and ‘description’ attributes. It starts an output buffer, runs the ‘output’ function with the provided attributes, and then returns the buffered output. This allows for the dynamic display of form content based on the specified attributes.

Shortcode: [wpforms]

Parameters

Here is a list of all possible wpforms shortcode parameters and attributes:

  • id – Unique identifier of the contact form.
  • title – The title of the form to be displayed.
  • description – The description of the form to be shown.

Examples and Usage

Basic example – The following shortcode is a simple usage of the WPForms plugin. It displays a form with the ID of 1 on your WordPress website.

[wpforms id=1 /]

Advanced examples

Display a form with a specific ID and title. In this scenario, WPForms attempts to load the form by its ID. If the form with the specified ID is not found, it will then try to load a form with the given title.

[wpforms id=1 title='Contact Us' /]

Display a form with a specific ID, title, and description. Similarly to the previous example, the form will first try to load by ID, if not found, it will try to load by title. The description parameter allows you to add a brief description of the form.

[wpforms id=1 title='Contact Us' description='This is our main contact form.' /]

Note: When using these shortcodes, make sure to replace the ID, title, and description with the actual values of your forms.

PHP Function Code

In case you have difficulties debugging what causing issues with [wpforms] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wpforms', [ $this, 'shortcode' ] );

Shortcode PHP function:

function shortcode( $atts ) {

		$defaults = [
			'id'          => false,
			'title'       => false,
			'description' => false,
		];

		$atts = shortcode_atts( $defaults, shortcode_atts( $defaults, $atts, 'output' ), 'wpforms' );

		ob_start();

		$this->output( $atts['id'], $atts['title'], $atts['description'] );

		return ob_get_clean();
	}

Code file location:

wpforms-lite/wpforms-lite/src/Frontend/Frontend.php

Conclusion

Now that you’ve learned how to embed the WPForms Lite Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *