Mailjet Email Marketing Shortcode

Below, you’ll find a detailed guide on how to add the Mailjet Email Marketing 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 Mailjet Email Marketing Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Mailjet Email Marketing Plugin and the shortcodes it provides:

Plugin Icon
Mailjet Email Marketing

"Mailjet Email Marketing is a powerful WordPress plugin that enables seamless integration of your site with the Mailjet service, enhancing your email marketing capabilities."

★★★✩✩ (40) Active Installs: 20000+ Tested with: 6.2.3 PHP Version: 5.6
Included Shortcodes:
  • [mailjet_form_builder]

Mailjet Email Marketing [mailjet_form_builder] Shortcode

The Mailjet Form Builder shortcode is a powerful tool in WordPress. It dynamically displays a Mailjet widget based on the user’s configuration. The shortcode uses ‘widget_id’ to identify the specific widget to display. If ‘widget_id’ is not defined, it defaults to the first widget id in the collection.

Shortcode: [mailjet_form_builder]

Parameters

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

  • widget_id – identifies the specific form widget to display

Examples and Usage

Basic example – A simple shortcode to display the first Mailjet form builder widget configured by the user.

[mailjet_form_builder /]

Advanced examples

Using the shortcode to display a specific Mailjet form builder widget by referencing its ID. This will display the widget associated with the given ‘widget_id’.

[mailjet_form_builder widget_id=2 /]

Using the shortcode to display multiple Mailjet form builder widgets by referencing their IDs. This will display the widgets associated with the given ‘widget_id’s.

[mailjet_form_builder widget_id=2,3,4 /]

Remember that the ‘widget_id’ attribute in the shortcode must match the actual ID of the Mailjet form builder widget configured by the user. If the ‘widget_id’ attribute is not defined in the shortcode, the first widget ID from the collection will be used.

PHP Function Code

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

Shortcode line:

add_shortcode('mailjet_form_builder', array($this, 'display_mailjet_form_builder_widget'));

Shortcode PHP function:

function display_mailjet_form_builder_widget(array $attr = [], string $tag = '')
    {
        \extract(shortcode_atts(['widget_id' => null], $attr, $tag));
        // GET All Mailjet widgets - to find the one that user actually configured with the shortcode
        $instance = get_option('mailjet_form_builder_widget_options');

        // In case we don't have 'widget_id' attribute in the shortcode defined by user - we use the first widget id from the collection
        if (empty($widget_id)) {
            $widgetIds = [];
            foreach (array_keys($instance) as $key) {
                if (is_int($key)) {
                    $widgetIds[] = $key;
                }
            }
            $widget_id = min($widgetIds);
        }
        ob_start();
        the_widget('MailjetWp\\MailjetPlugin\\WidgetFormBuilder\\WP_Mailjet_FormBuilder_Widget', $instance[(int)$widget_id]);
        return ob_get_clean();
    }

Code file location:

mailjet-for-wordpress/mailjet-for-wordpress/src/includes/Mailjet.php

Conclusion

Now that you’ve learned how to embed the Mailjet Email Marketing 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 *