Skip to content

Instantly share code, notes, and snippets.

View GavinJaynes's full-sized avatar

Gavin GavinJaynes

  • Brisbane
  • 08:16 (UTC -12:00)
View GitHub Profile
@GavinJaynes
GavinJaynes / gulpfile.js
Created June 3, 2016 04:37
Gulp File for Silver Stripe theme
// generated on 2016-06-02 using generator-gulp-webapp 1.1.1
import gulp from 'gulp';
import gulpLoadPlugins from 'gulp-load-plugins';
import browserSync from 'browser-sync';
import del from 'del';
import {stream as wiredep} from 'wiredep';
const $ = gulpLoadPlugins();
const reload = browserSync.reload;
@GavinJaynes
GavinJaynes / number-input-tweak.js
Last active February 16, 2023 16:18
Change WooCommerce number input ( Quantity ) to use custom styles using JavaScript. This can be used for any number field with the step attribute.
// Nominate the containing selector
var parentSelector = $('.quantity');
// If it's on the page
if( parentSelector.length ) {
// Get the original HTML
var numberInputs = parentSelector.html();
// Change number to text
var textInputs = numberInputs.replace('type="number"', 'type="text"');
// Plus button
@GavinJaynes
GavinJaynes / animate.css
Last active June 22, 2016 03:31
Simple animation for elements as they enter the view port. Update: Just use WOW.js
.selector {
width: 100%;
height: 300px;
margin: 40px;
background: black;
/* The defaults */
opacity: 0;
margin-top: 90px;
transition: all 500ms ease;
-moz-transition: all 500ms ease;
@GavinJaynes
GavinJaynes / string-changer.js
Created April 7, 2015 10:39
Changing strings in JS
// Slug maker
//===================================
function slugify (value) {
return value.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/_/g, '-') // Replace underscores with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
@GavinJaynes
GavinJaynes / get_current_url.php
Last active August 29, 2015 14:05
Get the current url - the WordPress way
<?php
global $wp;
$current_url = home_url(add_query_arg(array(),$wp->request));
@GavinJaynes
GavinJaynes / cusotm-conditional.php
Created June 19, 2014 09:35
Wordpress has built in conditional functions such as is_page() and is_front(), but sometimes it's not enough. This function checks if the current url contains a slug and returns true or false respectively.
/**
* This function checks if the page you're on is a certain page
* @param $slug the slug of the page you are checking for
*/
function is_this_page($slug) {
$current_url = home_url(add_query_arg(array()));
if (false !== strpos($current_url, $slug)) {
@GavinJaynes
GavinJaynes / wordpress-redirect.php
Created June 6, 2014 10:53
A WordPress redirect function where you can redirect using slugs or full urls. It also takes in an exceptions as an array of slugs.
<?php
// ====================================================
// -- HANDY REDIRECT FUNCTION
// -- Takes in 2 param:
// -- 1. String: slug and parent eg: parent-page/child-page/
// -- 2. Boolean: if it's just the slug or the full url
// -- 3. Array of strings: Any Exceptions
// ====================================================
function go_to( $destination, $full_url, $exceptions ) {