How to add sign up form to blog post

Hello,

I would like to add the MailChimp sign up form of my home page above my content in every blog posts. Is there a code I could use?

Also, I noticed my sign up form doesn’t appear the same way on desktop and mobile with the desktop version being prettier. The mobile version doesn’t look the same (in terms of how it displays, the color of my button, the quality, etc). Is there a way to fix that?

Thank you!

1 Like

Hi Stephanie,

I checked your homepage and didn’t see any form. Do you mind adding it back again so we can check.

To add the form in your every post, you can add the code below in your child theme’s functions.php



function add_my_form() {
    if(is_singular('post')) {
            echo '<div class="my-form">';
            echo do_shortcode('[x_subscribe form=8]'):
            echo '</div>';
    }  
}

add_action( 'x_after_the_content_begin', 'add_my_form', 10 );

Change [x_subscribe form=8] with your own shortcode

Hope that helps

1 Like

Hello,

I did not make it visible because I cant find a way to reduce the height/distance between the “name”, “email” and “button” in my form. I’m trying to work on it. Here is the code mailchimp gave me. I tried to paste it in your code but I think it is too long and I don’t have a shortcode… Any options? I can’t paste the code here it won’t show, but it’s the embedded form of mailchimp.

Hi Stephanie,

Do you mean the form generated from the MailChimp dashboard? Sorry, but we can not help styling that form, you need to style that from the MailChimp side.

You can modify the code above provided by Paul to cater the generated code from Mailchip.

function add_my_form() {
    if(is_singular('post')) { ?>
      <div class="sign-up mtl">
        <!-- PASTE YOUR MAILCHIMP FORM CODE HERE -->
      </div>
   <?php }  
}

add_action( 'x_after_the_content_end', 'add_my_form', 10 );

Replace the <!-- PASTE YOUR MAILCHIMP FORM CODE HERE --> with the actual generated code from MailChimp.

Or you can use the Email Form extension, connect it to your MailChimp account and create your Form from your admin dashboard and have the shortcode of the form.

Thanks,

1 Like

Thanks a lot! :slight_smile:

You’re welcome!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.