Optinmonster Shortcodes

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

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

Plugin Icon
Popup Builder by OptinMonster – WordPress Popups for Optins, Email Newsletters and Lead Generation

"Popup Builder by OptinMonster is a powerful WordPress plugin designed for opt-ins, email newsletters, and lead generation. It provides seamless popups to increase user engagement and conversions."

★★★★✩ (698) Active Installs: 1000000+ Tested with: 6.3.2 PHP Version: 5.3
Included Shortcodes:
  • [optin-monster]
  • [optin-monster-shortcode]
  • [optin-monster-inline]

Optinmonster [optin-monster] Shortcode

The OptinMonster shortcode is a powerful tool that enables the display of opt-in forms on your site. It connects with the OMAPI_Shortcodes_Shortcode class, handling exceptions gracefully.

Shortcode: [optin-monster]

Examples and Usage

Basic example – A straightforward usage of the OptinMonster shortcode would be to simply call it with an ID parameter. This ID should correspond to the ID of the OptinMonster campaign you want to display.

[optin-monster id="1" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'optin-monster', array( $this, 'shortcode' ) );

Shortcode PHP function:

function shortcode( $atts ) {
		global $post;
		$this->shortcode = new OMAPI_Shortcodes_Shortcode( $atts, $post );

		try {
			return $this->shortcode->handle();
		} catch ( Exception $e ) {
		}

		return '';
	}

Code file location:

optinmonster/optinmonster/OMAPI/Shortcode.php

Optinmonster [optin-monster-shortcode] Shortcode

The OptinMonster shortcode allows you to implement custom features in your WordPress site. It uses the ‘id’ attribute to run the v2 implementation.

Shortcode: [optin-monster-shortcode]

Parameters

Here is a list of all possible optin-monster-shortcode shortcode parameters and attributes:

  • id – Unique identifier for the specific opt-in form
  • slug – Replaces the ‘id’ as the unique identifier if ‘id’ is present

Examples and Usage

Basic example – A simple shortcode usage to display an OptinMonster campaign by referencing its ID.

[optin-monster-shortcode id="123" /]

Advanced examples

Here, we use the shortcode to display an OptinMonster campaign by referencing its slug, which is another unique identifier for each campaign. If the ID is not found, it will try to load the campaign by slug.

[optin-monster-shortcode slug="campaign-slug-1" /]

Another advanced example involves using the shortcode to display multiple OptinMonster campaigns by referencing their IDs. This can be useful if you want to display several related campaigns together.

[optin-monster-shortcode id="123" /]
[optin-monster-shortcode id="456" /]
[optin-monster-shortcode id="789" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'optin-monster-shortcode', array( $this, 'shortcode_v1' ) );

Shortcode PHP function:

function shortcode_v1( $atts ) {
		// Run the v2 implementation.
		if ( ! empty( $atts['id'] ) ) {
			$atts['slug'] = $atts['id'];
			unset( $atts['id'] );
		}

		return $this->shortcode( $atts );
	}

Code file location:

optinmonster/optinmonster/OMAPI/Shortcode.php

Optinmonster [optin-monster-inline] Shortcode

The OptinMonster Inline shortcode is used to generate and control inline campaigns. It interacts with specific attributes and the post to create a unique HTML output. This shortcode uses a function to create a shortcode object, apply filters to check output conditions, and handle inline campaigns. It ensures non-inline campaigns are rejected, maintaining the desired output.

Shortcode: [optin-monster-inline]

Examples and Usage

Basic example – The OptinMonster inline campaign shortcode can be used to display a specific inline campaign by referencing its ID. This is useful when you want to insert a specific opt-in form within your content.

[optin-monster-inline id="123"]

Advanced examples

1. Displaying an inline campaign with specific rules: In this example, the shortcode is used to display an inline campaign with specific rules. The rules can be defined as attributes in the shortcode. This is useful when you want to control the display of the campaign based on certain conditions.

[optin-monster-inline id="123" rule="rule_value"]

2. Displaying multiple inline campaigns: In this example, the shortcode is used to display multiple inline campaigns by referencing their IDs. This is useful when you want to display multiple opt-in forms within your content.

[optin-monster-inline id="123,456,789"]

PHP Function Code

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

Shortcode line:

add_shortcode( 'optin-monster-inline', array( $this, 'inline_campaign_shortcode_with_rules' ) );

Shortcode PHP function:

function inline_campaign_shortcode_with_rules( $atts = array() ) {
		global $post;

		$html            = '';
		$this->shortcode = new OMAPI_Shortcodes_Shortcode( $atts, $post );

		try {
			add_filter( 'optinmonster_check_should_output', array( $this, 'reject_non_inline_campaigns' ), 10, 2 );
			$html = $this->shortcode->handle_inline();
		} catch ( Exception $e ) {
		}

		remove_filter( 'optinmonster_check_should_output', array( $this, 'reject_non_inline_campaigns' ), 10, 2 );

		return $html;
	}

Code file location:

optinmonster/optinmonster/OMAPI/Shortcode.php

Conclusion

Now that you’ve learned how to embed the Optinmonster 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.

Comments

Leave a Reply

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