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.

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 id='SENDY-LIST-ID' width='150px']

Width is optional, it’ll go with 100% if you don’t specify it. If you don’t include id it’ll just break and do nothing.

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: 0.0.1
Author: Cohan Robinson
Author URI: https://cohanrobinson.com/
License: GPLv3
*/

function sendy_form ($atts) {
	$attribute = shortcode_atts( array(
	    'id' => 'xxx',
	    'width' => '100%'
	), $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="https://mailer.icnerd.com/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" />
		<div style="display:none;">
			<input type="text" name="hp" placeholder="HP" />
		</div>
		<input type="hidden" name="list" value="<?php echo $attribute['id']; ?>"/>
		<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');

Leave a Reply