Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Attaches ACF fields to single posts
*
* Filters output from http://wordpress.org/extend/plugins/json-api/o
* Requires ACF plugin
*/
function attach_acf_fields($response) {
// We need ACF plugin
@ChrisLTD
ChrisLTD / gulpfile.js
Created January 12, 2015 16:56
Gulpfile w/ cache buster replacement
var gulp = require('gulp');
var plumber = require('gulp-plumber'); // used for error catching during watch
var sass = require("gulp-sass");
var changed = require('gulp-changed'); // only move changed files
var replace = require("gulp-replace");
var concat = require("gulp-concat");
var sourcePaths = {
styles: ['./scss/*.scss'],
scripts: ['./js/savings_slider.js', './js/jw_custom.js'],
// Clear local storage is hash in URL is #clear_ls
if( window.location.hash.toLowerCase() == "#clear_ls" ) {
localStorage.clear();
console.log('local storage cleared');
}
@ChrisLTD
ChrisLTD / gist:f8bbdba2a8c35b6b0a61
Last active August 29, 2015 14:07
Getting started with Phantom CSS
https://github.com/Huddle/PhantomCSS
npm install phantomcss
sudo npm install -g casperjs
sudo npm install -g phantomjs
create minimally viable testsuite.js:
=========
@ChrisLTD
ChrisLTD / gist:28843a642766c78fb142
Created September 7, 2014 21:41
Sort wordpress categories by description field
<?php
$resource_terms = get_terms( 'section' );
// Sort terms by description field
function description_compare($a, $b) {
return $a->description - $b->description;
}
usort($resource_terms, "description_compare");
?>
<div class="resource-filter">
<a href="#" class="resource-filter-term" data-filter="article" data-filter-by=".resource">All</a>
@ChrisLTD
ChrisLTD / gulpfile.js
Last active February 27, 2016 18:13
Gulpfile with server, livereload, etc.
var gulp = require('gulp');
var plumber = require('gulp-plumber'); // used for error catching during watch
var less = require('gulp-less');
var swig = require('gulp-swig');
var webserver = require('gulp-webserver');
var changed = require('gulp-changed'); // only move changed files
var opn = require('opn'); // for opening the browser
var sourcePaths = {
styles: ['less/**/*.less'],
@ChrisLTD
ChrisLTD / gist:bf3173618d792279836e
Last active August 29, 2015 14:02
Placeholder test support
# Test for placeholder support
inputTest = document.createElement('input')
if inputTest.hasOwnProperty('placeholder')
$('html').addClass('placeholder')
else
$('html').addClass('no-placeholder')
<?php
// Function to regenerate the data and save the transients
function special_query(){
$special_query_results = new WP_Query( 'cat=5&order=random&tag=tech&post_meta_key=thumbnail' );
set_transient( 'special_query_results' , $special_query_results, 12 * HOUR_IN_SECONDS );
set_transient( 'special_query_results_no_expire' , $special_query_results, 99 * YEAR_IN_SECONDS );
return $special_query_results;
}
// Get any existing copy of our transient data
<?php
function truncate_with_end ($string, $max = 200, $rep = '') {
$len = strlen ($string);
if( $len <= $max ){
return $string;
}
$leave = $max - strlen ($rep);
return substr_replace($string, $rep, $leave);
}
@ChrisLTD
ChrisLTD / functions.php
Created May 8, 2014 16:22
Fix so you can preview ACF field changes in Wordpress admin
<?php
/*
Debug preview with custom fields
Taken from: http://support.advancedcustomfields.com/forums/topic/preview-solution/
See also: http://support.advancedcustomfields.com/forums/topic/2nd-every-other-post-preview-throws-notice/
*/
add_filter('_wp_post_revision_fields', 'add_field_debug_preview');
function add_field_debug_preview($fields){
$fields["debug_preview"] = "debug_preview";
return $fields;