Activecampaign Subscription Forms Shortcode

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

Before starting, here is an overview of the Activecampaign Subscription Forms Plugin and the shortcodes it provides:

Plugin Icon
ActiveCampaign – Forms, Site Tracking, Live Chat

"ActiveCampaign – Forms, Site Tracking, Live Chat is a powerful WordPress plugin that allows seamless integration of subscription forms, real-time site tracking, and live chat features on your website."

★★★★☆ (28) Active Installs: 70000+ Tested with: 6.3.2 PHP Version: 5.4
Included Shortcodes:

Activecampaign Subscription Forms [activecampaign] Shortcode

The ActiveCampaign shortcode is a powerful tool that allows the display of subscription forms on your website. The shortcode: [activecampaign] fetches form settings and displays the form based on the parameters passed. It offers flexibility with options like ‘static’ for a non-interactive form, ‘preview’ for preview mode, and ‘css’ to control styling. If no settings are saved, it falls back to widget options, ensuring a seamless user experience.

Shortcode: [activecampaign]

Parameters

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

  • form – Specifies the form to be displayed from the saved settings
  • static – If set to true, the form will not change or refresh
  • preview – If set to true, shows a preview of the form
  • css – If set to true, uses default styles; if false, does not apply any styles

Examples and Usage

Basic example – A simple usage of the shortcode to display a form with the ID of 1.

[activecampaign form=1 /]

Advanced examples

Displaying a form with ID 1 in static mode. The static mode means that the form will not update or change based on user interactions.

[activecampaign form=1 static=true /]

Displaying a form with ID 1 in preview mode. The preview mode means that the form will display as a preview, without any functionality.

[activecampaign form=1 preview=true /]

Displaying a form with ID 1 without any CSS styles. This is useful if you want to apply your own styles to the form.

[activecampaign form=1 css=false /]

Displaying a form with ID 1 in static mode, with preview mode and without any CSS styles.

[activecampaign form=1 static=true preview=true css=false /]

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("activecampaign", "activecampaign_shortcodes");

Shortcode PHP function:

function activecampaign_shortcodes($args)
{
    // check for Settings options saved first.
    $settings = get_option("settings_activecampaign");
    if ($settings) {
        if (isset($settings["forms"]) && $settings["forms"]) {
            if (isset($args) && isset($args["form"]) && isset($settings["forms"][$args["form"]])) {
                $form_id = $args["form"];
                $form = $settings["forms"][$form_id];

                $static = false;
                if (isset($args["static"]) && ($args["static"] === 1 || $args["static"] === '1' || $args["static"] === 'true')) {
                    $static = true;
                }

                $preview = false;
                if (isset($args["preview"]) && ($args["preview"] === 1 || $args["preview"] === '1' || $args["preview"] === 'true')) {
                    $preview = true;
                }

                // Use null default for undefined settings fallback
				$nostyles = null;
				if (isset($args["css"])) {
					if ($args["css"] === 1 || $args["css"] === '1' || $args["css"] === 'true') {
						$nostyles = false;
					} elseif ($args["css"] === 0 || $args["css"] === '0' || $args["css"] === 'false') {
						$nostyles = true;
					}
                }

                return activecampaign_form_source($settings, $form, $static, $nostyles, $preview);
            }
        }
        // Returning un-filtered tag for block editor eval
        return "[activecampaign]";
    } else {
        // try widget options.
        $widget = get_option("widget_activecampaign_widget");
        // it comes out as an array with other things in it, so loop through it
        if(!empty($widget)){
			foreach ($widget as $k => $v) {
				// look for the one that appears to be the ActiveCampaign widget settings
				if (isset($v["api_url"]) && isset($v["api_key"]) && isset($v["form_html"])) {
					$widget_display = $v["form_html"];
					return $widget_display;
				}
			}
        }
    }
    return "";
}

Code file location:

activecampaign-subscription-forms/activecampaign-subscription-forms/activecampaign.php

Conclusion

Now that you’ve learned how to embed the Activecampaign Subscription Forms 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 *