Adding a Sendy shortcode to WordPress

Just now I decided to give Sendy a go for my mail lists. I wanted something a bit more self hosted than your usual Mailchimps and something a bit more robust than Mailgun lists.

The only problem – Ain’t no plugins to add a Sendy form as a shortcode! So I wrote a plugin for it. It’s nothing major and only a single file plugin for now.


Update 2018/06/01: Updated the plugin to add the “url” attribute.. the original was er, sorta sending you to my mailer. Whups.


The raw code is here (in all honesty, to pad out the length of this post) and you can grab it as an easy upload-to-install plugin here -> sendy-shortcode.zip

Usage

[sendy url='SENDY-URL' id='SENDY-LIST-ID' width='150px']

Width is optional, it’ll go with 100% if you don’t specify it.

It generally wont work if you don’t specify URL and ID

  • URL is your sendy URL, the domain you installed sendy to – e.g. mine would be “https://mailer.icnerd.com” – You gotta include the http(s):// bit
  • ID is the Sendy List ID. You can find this on your lists page

It’s the ID column there, mine starting “3DMP” – if you hover over that you can grab and copy your ID

Naturally you can see it in action with my own mail list page (.. and of course, feel free to sign up!)

<?php
/*
Plugin Name: Sendy Shortcode
Plugin URI: https://cohanrobinson.com/
Description: Easy add Sendy subscribe forms using a shortcode
Version: 1.0.0
Author: Cohan Robinson
Author URI: https://cohanrobinson.com/
License: GPLv3
*/

function sendy_form ($atts) {
$attribute = shortcode_atts( array(
'id' => 'xxx',
'width' => '100%',
'url' => '',
), $atts );

ob_start();
?>
<style type="text/css">
.sendy-form {
width: <?php echo $attribute['width']; ?>;
}
.sendy-name {
width: <?php echo $attribute['width']; ?>;
}
.sendy-email {
width: <?php echo $attribute['width']; ?>;
}
.sendy-submit {
width: <?php echo $attribute['width']; ?>;
margin-top: 10px;
margin-bottom: 20px;
}
</style>
<form class='sendy-form' action="<?php echo $attribute['url']; ?>/subscribe" method="POST" accept-charset="utf-8">
<input class='sendy-name' type="text" name="name" placeholder="Name" />
<input class='sendy-email' type="email" name="email" placeholder="Email address" />
<input type="hidden" name="list" value="<?php echo $attribute['id']; ?>"/>
<div style="display:none;">
<input type="text" name="hp" placeholder="HP" />
<input type="text" name="gdpr" value="true" />
</div>
<input type="hidden" name="subform" value="yes"/>
<input class='sendy-submit' type="submit" name="submit" />
</form>
<?php
return ob_get_clean();
}

add_shortcode('sendy', 'sendy_form');

2 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.