Below, you’ll find a detailed guide on how to add the Happyforms 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 Happyforms Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Happyforms Plugin and the shortcodes it provides:
"Happyforms is a versatile Form Builder plugin, designed to connect you with visitors, expand your email list, and facilitate payments. It's the ultimate tool for seamless user engagement and transaction handling on WordPress."
- [happyforms id="form_id"]
Happyforms [happyforms id=”form_id”] Shortcode
The HappyForms shortcode allows you to display a specific form within your content. It retrieves the form based on the ID provided and renders it according to the asset mode. The asset mode varies depending on the context – the classic editor, customize screen, or block editor. If the form is set to ‘modal’, it won’t be displayed.
Shortcode: [happyforms id="form_id"]
Parameters
Here is a list of all possible happyforms id=”form_id” shortcode parameters and attributes:
id
– Represents the specific contact form’s unique identifiermodal
– Controls whether the form will appear in a modal windowasset_mode
– Determines the form’s display mode, can be complete, admin, or preview
Examples and Usage
Basic example – Display a HappyForms form by referencing its ID
[happyforms id=123 /]
This shortcode will render the HappyForms form with the ID of 123 on your WordPress page or post. Ensure that you replace “123” with the actual ID of your form.
Advanced examples
Example 1 – Load a form in admin mode
[happyforms id=123 mode="admin" /]
This shortcode will load the HappyForms form with the ID of 123 in admin mode. This is useful when you want to preview the form in the admin dashboard.
Example 2 – Load a form in complete mode
[happyforms id=123 mode="complete" /]
This shortcode will load the HappyForms form with the ID of 123 in complete mode. This mode is typically used when the form is ready to be published and viewed by your website visitors.
Please note that in the above examples, you need to replace “123” with the actual ID of your form and “mode” with the appropriate mode you want to load the form in. The available modes are “admin” and “complete”.
PHP Function Code
In case you have difficulties debugging what causing issues with [happyforms id="form_id"]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( $this->branded_shortcode, array( $this, 'handle_shortcode' ) );
Shortcode PHP function:
function handle_shortcode( $attrs ) {
if ( ! isset( $attrs['id'] ) ) {
return;
}
$form_id = intval( $attrs['id'] );
$form_controller = happyforms_get_form_controller();
$form = $form_controller->get( $form_id );
if ( empty( $form ) ) {
return '';
}
if ( happyforms_get_form_property( $form, 'modal' ) ) {
return '';
}
$asset_mode = HappyForms_Form_Assets::MODE_COMPLETE;
// Classic editor
if ( is_admin() ) {
$asset_mode = HappyForms_Form_Assets::MODE_ADMIN;
}
// Customize screen
if ( happyforms_is_preview() ) {
$asset_mode = HappyForms_Form_Assets::MODE_ADMIN;
}
// Block editor
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
$asset_mode = HappyForms_Form_Assets::MODE_ADMIN;
}
$asset_mode = apply_filters( 'happyforms_asset_mode', $asset_mode );
$output = $form_controller->render( $form, $asset_mode );
return $output;
}
Code file location:
happyforms/happyforms/core/classes/class-happyforms-core.php
Conclusion
Now that you’ve learned how to embed the Happyforms 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.
Leave a Reply