If you have a custom theme or are looking to integrate with WPChimp, we have some tools for you.
WPChimp provides two template tags.
wpchimp_form_exists
This template tag lets you check if a form exists. You pass it the name of your form and it returns true
if the form exists and false
if there is no form with that name.
The full signature is:
function wpchimp_form_exists($form_name)
Where, $form_name
is a string.
Example:
<?php if(wpchimp_form_exists('My Form')) { ?>
<span>We have the form!</span>
<?php } ?>
wpchimp_form
This template tag will render a form if it exists. You pass it the name of your form and it produces the HTML for that form.
If a form with the provided name does not exist, this tag does not output anything.
The full signature is:
function wpchimp_form($form_name, $echo=true)
Where:
$form_name
is the name of the form that you want to render, and $echo
is a boolean parameter that tells the function to output the HTML directly or to return it as a string.
By default $echo
is true, meaning that if you only pass the form’s name, the tag will output the HTML directly.
Example:
<?php wpchimp_form('My Form'); ?>
Or, without outputting the form:
<?php $form = wpchimp_form('My form'); ?>
One last example
<?php if(wpchimp_form_exists('My Form')) { ?>
<div>
<h3>Subscribe to our cool mailing list!</h3>
<?php wpchimp_form('My Form'); ?>
</div>
<?php } ?>