Skip to content

Instantly share code, notes, and snippets.

@LiamBailey
Last active August 24, 2017 12:32
Show Gist options
  • Save LiamBailey/3602b6c5a8e2b134c5b39765065d6fa4 to your computer and use it in GitHub Desktop.
Save LiamBailey/3602b6c5a8e2b134c5b39765065d6fa4 to your computer and use it in GitHub Desktop.
jQuery(function($) {
var beforeButton = $("<i class='incr-button fa fa-minus-circle fa-2x' />");
var beforeButtonClick = function() {
var input = $(this).next();
input.val(new Number(input.val()) - 1);
}
var afterButton = $("<i class='incr-button fa fa-plus-circle fa-2x' />");
var afterButtonClick = function() {
var input = $(this).prev();
input.val(new Number(input.val()) + 1);
}
$("input[type='number']").before(beforeButton);
$("input[type='number']").after(afterButton);
})
/* Styles for buttons */
.fa-plus-circle {
color: green
}
.fa-minus-circle {
color: green
}
<?php
/**
* Plugin Name: Buttons on my Number Inputs
* Author: Liam Bailey (Webby Scots)
* Description: Adds nice Font Awesome buttons to number inputs on the site
* Author URI: https://webbyscots.com
**/
add_action('wp_enqueue_scripts', 'wswp_add_scripts');
function wswp_add_scripts() {
wp_enqueue_script('font-awesome', 'https://use.fontawesome.com/9f67fc414e.js');
wp_enqueue_style('my-plugin-css', plugins_url('style.css', __FILE__), NULL, time());
wp_enqueue_script('my-plugin-js', plugins_url('script.js',__FILE__), array('jquery'), time());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment