The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Optin Form Code to be placed in functions.php

Highlighted
Occasional Participant

Optin Form Code to be placed in functions.php

Hi there,

 

I have signed up to give Constant Contact a go. I am using the trial version to get the hang of it while working on my site.

 

I have used the sign up tool and embedded the code in the sidebar.  It works.  I can see 'thanks for signing up' message.

 

But I have created the separate custom code to be used at the end of my posts.  How do I gain access to the opt-in form code?

 

Here is the code:

<!-- Add your opt-in form code here! Example: -->
<div class="form-container"</div>
<div class="form-container-post-title">Like what you read? Subscribe to get FREE blog updates.</div>
<form>
<input type="text" name="email" placeholder="Enter your email">
<input type="submit" name="submit" value="Subscribe">
</form>

<?php
// Add the opt-in form after the post content.
return $content . ob_get_clean();
}
add_filter( 'the_content', 'add_my_optin', 125 );

?>

 

Thanks

 

Bonnie

 

6 REPLIES 6
Highlighted
Employee

Re: Optin Form Code to be placed in functions.php

Hi Bonnie,

 

Welcome aboard, and I'm glad the opt-in code is working! I'm afraid we don't host any funcitons.php code on our side. I believe that code would be owned and controlled by your web hosting company.

 

Sorry I'm not much help, but hopefully your website hoster can tell you how to access that.

 

Best Regards,

Shannon Wallace

Partner API Support Engineer

Highlighted
Occasional Participant

Re: Optin Form Code to be placed in functions.php

Hi Shannon,

 

The php script was copied and pasted from another blog.  The functions.php of my Wordpress theme can be  customized.

 

<!-- Add your opt-in form code here! Example: -->

What needs to go there is your code to integrate it.  

 

function add_my_optin( $content ) {	$post_type = get_post_type();
	
	// Return the unfiltered content if we're not on a post.
	if ( $post_type != 'post' ) {
		return $content;
	}	
	ob_start();
	?>
	
	<!-- Add your opt-in form code here! Example: -->
	<form>
		<input type="text" name="email" placeholder="Enter your email">
		<input type="submit" name="submit" value="Subscribe">
	</form>
	
	<?php
	// Add the opt-in form after the post content.
	return $content . ob_get_clean();
}add_filter( 'the_content', 'add_my_optin', 125 );

 

Highlighted
Employee

Re: Optin Form Code to be placed in functions.php

Hi Bonnie,

 

I see; sorry I misunderstood. You can try replacing this:

 

<form>
	<input type="text" name="email" placeholder="Enter your email">
	<input type="submit" name="submit" value="Subscribe">
</form>

With a portion of something we call "Embed Code," which is available by logging into your account (it's customized for each account so we know which account to send the contacts into). To find the Embed Code, login to your account and go to Contacts>Sign-up Tools>Actions (dropdown next to 'Sign-up Form')>Embed Code. You can also use the 'Actions' dorpdown to edit the signup form to choose what fields your form will include; do that before copying the Embed Code.

 

Once you've copied the Embed Code, there will be more code there than you will need for this Wordpress code. You'll only want the portion of the Embed Code that starts with <form> and ends with </form>.

 

Copy and paste that in where the example form code is, and test it out. It's possible that this Wordpress method isn't compatible with us, but I can't say for sure. If that's the case, and you don't see this working, I'd recommend using one of these Wordpress plugins that's specifically designed with us in mind.

 

I hope that helps!

 

Best Regards,

Shannon Wallace

Partner API Support Engineer

 

Highlighted
Occasional Participant

Re: Optin Form Code to be placed in functions.php

Hi Shannon,

 

I am awared of your code that the Sign Up Tools has generated and I used it in a text widget on the sidebar of my Wordpress blog.

 

But I wanted to customize the opt-in box that I want below my blog posts.  And something goes 'here':  
<!-- Add your opt-in form code here! --> in the function.php.

 

<!--Begin CTCT Sign-Up Form-->
<!-- EFD 1.0.0 [Fri Dec 25 00:47:27 EST 2015] -->
<link rel='stylesheet' type='text/css' href='https://static.ctctcdn.com/h/contacts-embedded-signup-assets/1.0.2/css/signup-form.css'>
<div class="ctct-embed-signup" style="font: 16px Helvetica Neue, Arial, sans-serif; font: 1rem Helvetica Neue, Arial, sans-serif; line-height: 1.5; -webkit-font-smoothing: antialiased;">
<div style="color:#808080; background-color:#FFFFFF; border-radius:5px;">
<span id="success_message" style="display:none;">
<div style="text-align:center;">Thanks for signing up!</div>
</span>
<form data-id="embedded_signup:form" class="ctct-custom-form Form" name="embedded_signup" method="POST" action="https://visitor2.constantcontact.com/api/signup">
<h2 style="margin:0;">Subscribe to Marketing Articles by Email</h2>
<p></p>
<!-- The following code must be included to ensure your sign-up form works properly. -->
<input data-id="ca:input" type="hidden" name="ca" value="79ce0f16-fe76-4e45-b032-80460c1de9dd">
<input data-id="list:input" type="hidden" name="list" value="1421677467">
<input data-id="source:input" type="hidden" name="source" value="EFD">
<input data-id="required:input" type="hidden" name="required" value="list,email">
<input data-id="url:input" type="hidden" name="url" value="">
<p data-id="Email Address:p" ><input data-id="Email Address:input" type="text" name="email" value="" maxlength="80" placeholder="Enter your email" ></p>
<button type="submit" class="Button ctct-button Button--block Button-secondary" data-enabled="enabled">Subscribe</button>
</form>
</div>
</div>
<script type='text/javascript'>
var localizedErrMap = {};
localizedErrMap['required'] = 'This field is required.';
localizedErrMap['ca'] = 'An unexpected error occurred while attempting to send email.';
localizedErrMap['email'] = 'Please enter your email address in format.';
localizedErrMap['birthday'] = 'Please enter birthday in MM/DD format.';
localizedErrMap['anniversary'] = 'Please enter anniversary in MM/DD/YYYY format.';
localizedErrMap['custom_date'] = 'Please enter this date in MM/DD/YYYY format.';
localizedErrMap['list'] = 'Please select at least one email list.';
localizedErrMap['generic'] = 'This field is invalid.';
localizedErrMap['shared'] = 'Sorry, we could not complete your sign-up. Please contact us to resolve this.';
localizedErrMap['state_mismatch'] = 'Mismatched State/Province and Country.';
localizedErrMap['state_province'] = 'Select a state/province';
localizedErrMap['selectcountry'] = 'Select a country';
var postURL = 'https://visitor2.constantcontact.com/api/signup';
</script>
<script type='text/javascript' src='https://static.ctctcdn.com/h/contacts-embedded-signup-assets/1.0.2/js/signup-form.js'></script>
<!--End CTCT Sign-Up Form-->

 

Thanks 

 

Bonnie

Highlighted
Employee

Re: Optin Form Code to be placed in functions.php

Hi Bonnie,

 

Sorry if I'm missing something here. This is the complete code I think you want to try. If this doesn't work, I'd recommend one of the Wordpress plugins listed here

 

function add_my_optin( $content ) {	$post_type = get_post_type();
	
	// Return the unfiltered content if we're not on a post.
	if ( $post_type != 'post' ) {
		return $content;
	}	
	ob_start();
	?>

<form data-id="embedded_signup:form" class="ctct-custom-form Form" name="embedded_signup" method="POST" action="https://visitor2.constantcontact.com/api/signup">
<h2 style="margin:0;">Subscribe to Marketing Articles by Email</h2>
<p></p>
<!-- The following code must be included to ensure your sign-up form works properly. -->
<input data-id="ca:input" type="hidden" name="ca" value="79ce0f16-fe76-4e45-b032-80460c1de9dd">
<input data-id="list:input" type="hidden" name="list" value="1421677467">
<input data-id="source:input" type="hidden" name="source" value="EFD">
<input data-id="required:input" type="hidden" name="required" value="list,email">
<input data-id="url:input" type="hidden" name="url" value="">
<p data-id="Email Address:p" ><input data-id="Email Address:input" type="text" name="email" value="" maxlength="80" placeholder="Enter your email" ></p>
<button type="submit" class="Button ctct-button Button--block Button-secondary" data-enabled="enabled">Subscribe</button>
</form> <?php // Add the opt-in form after the post content. return $content . ob_get_clean(); }add_filter( 'the_content', 'add_my_optin', 125 );

 

 

Best Regards,

Shannon Wallace

Partner API Support Engineer

Highlighted
Occasional Participant

Re: Optin Form Code to be placed in functions.php

Hi Shannon,

 

Your code works but I want to customize it.  I have no intention of using those plugins.  I contacted the coder who came up with that php script.  

 

Thanks for your help anyway.

 

Cheers

 

Bonnie

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured