Skip to content

Instantly share code, notes, and snippets.

View kjbrum's full-sized avatar
🤘

Kyle Brumm kjbrum

🤘
View GitHub Profile
@kjbrum
kjbrum / webkit-autofill.css
Created December 19, 2014 20:04
Change the color of the ugly autofill background for webkit.
input:-webkit-autofill,
textarea:-webkit-autofill,
select:-webkit-autofill {
-webkit-box-shadow: 0 0 0 1000px white inset;
}
@kjbrum
kjbrum / ajaxImagesLoaded.js
Last active August 29, 2015 14:12
Run something after images from ajax are loaded.
$(document).ready(function() {
// Check for all images to be loaded
$.fn.imagesLoaded = function() {
var dfds = [];
var $imgs = this.find('img[src!=""]');
$imgs.each(function() {
var dfd = $.Deferred();
dfds.push(dfd);
var img = new Image();
@kjbrum
kjbrum / wp-automated-cache-busting.php
Last active January 15, 2022 19:31
Automated Cache Busting. This works by adding the file's change time to the end of the URL (last argument of the call)
<?php
/* For Themes */
wp_enqueue_style('slug', get_template_directory_uri().'/css/slug.css', array(), filemtime(get_template_directory().'/css/slug.css'));
wp_enqueue_script('slug', get_template_directory_uri().'/js/slug.js', array(), filemtime(get_template_directory().'/js/slug.js'));
/* For Plugins */
wp_enqueue_style('slug', plugin_dir_url(__FILE__).'css/slug.css', array(), filemtime(plugin_dir_path(__FILE__).'css/slug.css'));
wp_enqueue_script('slug', plugin_dir_url(__FILE__).'js/slug.js', array(), filemtime(plugin_dir_path(__FILE__).'js/slug.js'));
@kjbrum
kjbrum / downloadImages.js
Last active August 29, 2015 14:15
Save multiple images on a webpage.
function saveFile(url) {
var filename = url.substring(url.lastIndexOf("/") + 1).split("?")[0];
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function() {
var a = document.createElement('a');
a.href = window.URL.createObjectURL(xhr.response);
a.download = filename;
a.style.display = 'none';
document.body.appendChild(a);
@kjbrum
kjbrum / wp_gravity_forms_add_empty_dropdown_option.php
Last active March 22, 2021 23:23
Add a blank option to a Gravity Forms select element.
<?php
/**
* Add a blank option to a Gravity Forms dropdown
*
* @param object $form The Gravity Form
* @return object $form The modified Gravity Form
*/
function wp_gravity_forms_add_empty_dropdown_option( $form ) {
// Select the correct form, then set the id of the field(s) we need to change
if( $form['id'] == 1 ) {
@kjbrum
kjbrum / wp_acf_load_field_choices.php
Last active December 28, 2016 05:17
Add custom options to an ACF field.
<?php
/**
* ACF Load Field Choices.
*
* @param array $field The field that we are going to add options to
* @return array $field The field we modified
*/
function acf_load_field_choices( $field ) {
// Reset choices
$field['choices'] = array();
@kjbrum
kjbrum / wp_excerpt_length.php
Last active May 21, 2016 02:18
Create a custom length excerpt.
<?php
/**
* Create a custom length excerpt.
*
* @param integer $limit How many words you want returned
* @return string $content The content string
*/
function wp_excerpt_length( $limit=50 ) {
$content = get_the_content();
@kjbrum
kjbrum / socialShare.js
Last active July 13, 2024 22:33
Create a popup for sharing something on social media.
/**
* Social sharing popup window
*/
var jsSocialShares = document.querySelectorAll('.social-share a');
if(jsSocialShares) {
[].forEach.call(jsSocialShares, function(anchor) {
anchor.addEventListener('click', function(e) {
var url = this.href,
width = 500,
@kjbrum
kjbrum / wp_get_attachment_image_data.php
Last active April 21, 2022 09:10
Create an array of an attachment image's data.
<?php
/**
* Create an array of an attachment image's data.
*
* @param int $id The id of the attachment image
* @return array $image An array of all the image data
*/
function wp_get_attachment_image_data( $id=null ) {
$image = array();
@kjbrum
kjbrum / csv_to_array.php
Last active July 4, 2018 17:04
Create an associative array from a csv file.
<?php
/**
* Create an associative array from a csv file.
*
* @param file $file The csv file that is going to be parsed
* @return array $data An associative array with the csv headings as keys
*/
function csv_to_array( $file ) {
$data = array();
$header = null;