Below, you’ll find a detailed guide on how to add the MC4WP: Mailchimp for WordPress 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 MC4WP: Mailchimp for WordPress Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the MC4WP: Mailchimp for WordPress Plugin and the shortcodes it provides:
"MC4WP: Mailchimp for WordPress is a user-friendly plugin designed to integrate your WordPress site with Mailchimp effortlessly. It simplifies email marketing by automating sign-ups from your WP platform."
- [Mailchimp-for-WP]
MC4WP: Mailchimp for WordPress [Mailchimp-for-WP] Shortcode
The Mailchimp-for-WP shortcode integrates Mailchimp with your WordPress site. It accepts attributes like ‘id’, ‘lists’, ’email_type’, ‘element_id’, and ‘element_class’. It generates a form to capture user details and subscribe them to your Mailchimp lists. The ’email_type’ attribute specifies the format of the email to be sent.
Shortcode: [Mailchimp-for-WP]
Parameters
Here is a list of all possible Mailchimp-for-WP shortcode parameters and attributes:
id
– A unique identifier of the contact formlists
– Specific MailChimp lists to target with the formemail_type
– Determines the format of emails being sentelement_id
– Specifies the HTML element ID for the formelement_class
– Defines the CSS class for styling the form
Examples and Usage
Basic example – A simple shortcode that uses the ‘id’ attribute to output a specific form.
[mc4wp_form id="123" /]
Advanced examples
Displaying a form by specifying both ‘id’ and ’email_type’. The ’email_type’ attribute can be used to specify the type of email format (HTML or Text) that the user will receive.
[mc4wp_form id="123" email_type="html" /]
Displaying a form with specific ‘id’, ’email_type’, and ‘lists’. The ‘lists’ attribute can be used to specify the MailChimp lists that the form should subscribe to.
[mc4wp_form id="123" email_type="html" lists="abc123,def456" /]
Displaying a form with specific ‘id’, ’email_type’, ‘lists’, and ‘element_id’. The ‘element_id’ attribute can be used to specify a unique ID for the form element, which can be useful for custom CSS styling.
[mc4wp_form id="123" email_type="html" lists="abc123,def456" element_id="myForm" /]
Displaying a form with all available attributes. This example includes ‘id’, ’email_type’, ‘lists’, ‘element_id’, and ‘element_class’. The ‘element_class’ attribute can be used to specify a custom CSS class for the form element.
[mc4wp_form id="123" email_type="html" lists="abc123,def456" element_id="myForm" element_class="myCustomClass" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [Mailchimp-for-WP]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( self::SHORTCODE, array( $this, 'shortcode' ) );
Shortcode PHP function:
function shortcode( $attributes = array(), $content = '' ) {
$default_attributes = array(
'id' => '',
'lists' => '',
'email_type' => '',
'element_id' => '',
'element_class' => '',
);
$attributes = shortcode_atts(
$default_attributes,
$attributes,
self::SHORTCODE
);
$config = array(
'element_id' => $attributes['element_id'],
'lists' => $attributes['lists'],
'email_type' => $attributes['email_type'],
'element_class' => $attributes['element_class'],
);
return $this->output_form( $attributes['id'], $config, false );
}
Code file location:
mailchimp-for-wp/mailchimp-for-wp/includes/forms/class-output-manager.php
Conclusion
Now that you’ve learned how to embed the MC4WP: Mailchimp for WordPress 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