Skip to content

Instantly share code, notes, and snippets.

@keithdevon
keithdevon / cache-busting-script.php
Created November 20, 2014 15:56
WordPress script and style cache busting!
add_action('wp_enqueue_scripts', 'load_your_css');
function load_your_css(){
if(!is_admin()){
$css_link = get_stylesheet_directory_uri() . '/style.css';
$css_file = get_stylesheet_directory() . '/style.css';
wp_enqueue_style('theme-style', $css_link, array(), filemtime($css_file), 'all');
}
}
@keithdevon
keithdevon / allow-region.php
Created October 7, 2014 10:41
Allow region query in Relevanssi search
// add region query variable
add_filter('query_vars', 'introduce_region_qv');
function introduce_region_qv($qv) {
$qv[] = 'job_region';
return $qv;
}
// filter relevanssi based on job_region query
@keithdevon
keithdevon / relevanssi-custom-functions.php
Last active January 25, 2024 12:51
Relevanssi job search
// filter relevanssi based on job_region query
add_filter('relevanssi_modify_wp_query', 'region_tax_query');
function region_tax_query($query) {
$tax_query = array();
if (!empty($query->query_vars['job_region'])) {
$tax_query[] = array(
'taxonomy' => 'region',
'field' => 'id',
'terms' => $query->query_vars['job_region']
@keithdevon
keithdevon / manual-gravity-forms
Created September 25, 2014 21:05
Manually create entries and send notifications with Gravity Forms
<?php
// Manually create entries and send notifications with Gravity Forms
$form_id = 10;
// add entry
$entry = array(
"form_id" => $form_id,
"1" => "Entry for field ID 1",
@keithdevon
keithdevon / image.html
Created September 25, 2014 12:36
Responsive vertically centered images
<div class="responsive-container responsive-container--square">
<img class="vertically-centered" src="path/to/image.jpg" />
</div>
@keithdevon
keithdevon / custom-template.php
Created September 24, 2014 10:27
Load WordPress page templates from a plugin
// This is the page template file
@keithdevon
keithdevon / lazy-load
Last active December 22, 2017 00:52
Lazy loading WordPress images
// make sure this script is called in the footer of your document
function inView(image){
var $image = jQuery(image),
view_top = jQuery(window).scrollTop() - 300,
view_bottom = view_top + jQuery(window).height() + 600,
height = $image.height(),
_top = $image.offset().top,
_bottom = _top + height;
return height > 0 && _top <= view_bottom && _bottom >= view_top;
@keithdevon
keithdevon / backgroundsize.min.htc
Created August 22, 2014 15:30
Full screen background images 2
<!-- background-size-polyfill v0.2.0 | (c) 2012-2013 Louis-Rémi Babé | MIT License -->
<PUBLIC:COMPONENT lightWeight="true">
<PUBLIC:ATTACH EVENT="oncontentready" ONEVENT="o.init()" />
<PUBLIC:ATTACH EVENT="ondocumentready" ONEVENT="o.init()" />
<PUBLIC:ATTACH EVENT="onpropertychange" ONEVENT="o.handlePropertychange()" />
<PUBLIC:ATTACH EVENT="ondetach" ONEVENT="o.restore()" />
<PUBLIC:ATTACH EVENT="onresize" FOR="window" ONEVENT="o.handleResize()" />
<PUBLIC:EVENT NAME="onbackgroundupdate" ID="updateEvent" />
<script type="text/javascript">
var o;!function(a,b){var c=/url\(["']?(.*?)["']?\)/,d=/^\s\s*/,e=/\s\s*$/,f=/\s\s*/g,g=/%$/,h={top:0,left:0,bottom:1,right:1,center:.5},i=a.document,j="data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",k="background-size-polyfill",l=function(){},m=100,n,p,q,r;function s(){var b=i.createElement("div"),c=i.createElement("img"),d=b.style,e=a.style,f=a.currentStyle,g=a.bgsExpando,h=a.firstChild;g&&(g.restore&&(e.backgroundImage=g.restore.back
@keithdevon
keithdevon / full-screen-bg
Created August 22, 2014 13:54
Full screen background images
html {
background: url('http://placebear.com/1200/800') no-repeat center center fixed;
background-size: cover;
height: 100%;
overflow: hidden;
}
body {
height:100%;
overflow: scroll;
@keithdevon
keithdevon / cpts_in_main_query
Created August 13, 2014 13:29
Custom post types in home and blog pages
// Add custom post types to the home and blog pages
// change 'cpt1' and 'cpt2' to your post type names
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'post', 'cpt1', 'cpt2' ) );