Add Mailchimp subscribe form to all posts automatically

To automatically add a sign-up form to all your posts, go and edit the form you would like to show and open up the Settings tab.

From there, locate the Automatically add this form to posts in the following category setting and pick a category. Then save the form to update your settings.

That will automatically add the given sign-up form to the end of all posts in the chosen category.

Manually adding a form to (some) posts

Alternatively, you can use code to add a sign-up form to (some) posts. The following snippet should help you accomplish this.

Please make sure to change the $form_id variable to the actual ID of the form you would like to show. If you omit this line, your default form will be showed.

/**
 * Adds a form to the end of all single posts
 *
 * @param string $content
 * @return string $content
 */
function myprefix_add_form_to_posts( $content ) {
    // Change to ID of the form you want to add
    $form_id = 0;

    // Check if this is a single post.
    if ( is_singular('post') ) {
        // Add the form to the end of the post content.
        $content .= mc4wp_get_form( $form_id );
    }

    // Returns the content.
    return $content;
}
add_filter('the_content', 'myprefix_add_form_to_posts');