Below, you’ll find a detailed guide on how to add the Ninja Forms Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Ninja Forms Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Ninja Forms Plugin and the shortcodes it provides:
"Ninja Forms Contact Form is a user-friendly WordPress plugin. It allows you to create customizable forms with its innovative drag-and-drop form builder feature. Ideal for all WordPress users."
- [nf_preview]
- [ninja_form]
Ninja Forms [nf_preview] Shortcode
The Ninja Forms shortcode, ‘nf_preview’, is designed to display a form preview. It’s triggered by the shortcode: [nf_preview]. This shortcode calls the ‘display_form_preview’ function which checks if the ‘id’ attribute is set. If it’s not, it returns an error message. However, if it’s set, it uses the Ninja_Forms function to display the form associated with that ‘id’. This output is then returned and displayed on the page.
Shortcode: [nf_preview]
Parameters
Here is a list of all possible nf_preview shortcode parameters and attributes:
id
– The specific contact form’s unique identifier
Examples and Usage
Basic example – A simple usage of the shortcode to display a form by its ID.
[nf_preview id=1 /]
PHP Function Code
In case you have difficulties debugging what causing issues with [null]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'nf_preview', array( $this, 'display_form_preview' ) );
Shortcode PHP function:
function display_form_preview( $atts = array() )
{
if( ! isset( $atts[ 'id' ] ) ) return $this->display_no_id();
ob_start();
Ninja_Forms()->display( $atts['id'], TRUE );
return ob_get_clean();
}
Code file location:
ninja-forms/ninja-forms/includes/Display/Shortcodes.php
Ninja Forms [ninja_form] Shortcode
The Ninja_Forms shortcode is a powerful tool for displaying forms on the front-end of your WordPress site. It uses the ‘display_form_front_end’ function to render the form associated with the given ID.
Shortcode: [ninja_form]
Parameters
Here is a list of all possible ninja_form shortcode parameters and attributes:
id
– Unique identifier for the specific Ninja Form to be displayed
Examples and Usage
Basic example – A simple usage of the ninja_form shortcode to display a form with a specific ID.
[ninja_form id=3 /]
Advanced examples
Displaying a form by referencing both ID and title. The form will first try to load by ID, but if not found, it will try to load by title. Note that the ‘title’ attribute is not a built-in feature of the Ninja Forms shortcode and would require additional customization of the shortcode function.
[ninja_form id=3 title="Contact Form" /]
Displaying a form with a custom error message when the form ID is not found. This would also require additional customization of the shortcode function to support the ‘error_message’ attribute.
[ninja_form id=3 error_message="Sorry, the form could not be found." /]
PHP Function Code
In case you have difficulties debugging what causing issues with [ninja_form]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'ninja_form', array( $this, 'display_form_front_end' ) );
Shortcode PHP function:
function display_form_front_end( $atts = array() )
{
if( ! isset( $atts[ 'id' ] ) ) return $this->display_no_id();
ob_start();
Ninja_Forms()->display( $atts['id'] );
return ob_get_clean();
}
Code file location:
ninja-forms/ninja-forms/includes/Display/Shortcodes.php
Conclusion
Now that you’ve learned how to embed the Ninja Forms Plugin shortcodes, 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.
Leave a Reply