Add mailchimp signup form

Hello,

I would like to add mailchimp’s sign form code onto my blog post pages only. I had in mind that something like this would work under the child theme in functions.php.

function mailchimp_signup_code() { ?>

<----------Mailchimp code here.---->

<?php }
add_action( ‘wp_head’, ‘mailchimp_signup_code’ );

Could you please let me know if that’s the right idea? Additionally, I want the code to be applied to blog posts only or exclude certain page types. How can I do that? I am using the renew stack.

Your help is greatly appreciated!

Thanks

Hey @ayham,

Your code is for wp_head. Our theme’s filter to add content after the content is this x_after_the_content_end. You should use the WordPress Conditional Tag is_singular('post'). For more conditional tags, please see this documentation from Wordpress.org https://codex.wordpress.org/Conditional_Tags.

The code you need would look like the following:

/*  After Post Content */

add_action('x_after_the_content_end', 'add_recent_post_shortcode');

function add_recent_post_shortcode() { 
  if (is_singular('post')) { ?>
    <----------Mailchimp code here.---->
  <?php }
}

Hope that helps.

Fantastic. It works.

Thank you for your prompt response.

We are delighted to assist you with this.

Cheers!

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