Skip to content

Instantly share code, notes, and snippets.

@gyrus
gyrus / pilau_wp_head.php
Last active August 29, 2015 14:19
Wrapper for wp_head() which manages SSL
/**
* Wrapper for wp_head() which manages SSL
*
* @uses wp_head()
* @param bool $ssl
* @return void
*/
function pilau_wp_head( $ssl = false ) {
if ( ! $ssl || WP_LOCAL_DEV ) {
@gyrus
gyrus / pilau_ie10classes.js
Created April 8, 2015 21:13
jQuery HTML classes for IE 10+
/*
* A hack to add classes to the HTML element (a la Paul Irish) for IE 10+
* IE 10 and over no longer support conditional classes. However, sometimes
* you still need to target IE above 9!
*/
jQuery( document ).ready( function( $ ) {
var html = $( html );
if ( /MSIE 1[01]\.\d+;/.test( navigator.userAgent ) || /Trident/.test( navigator.userAgent ) ) {
html.addClass( 'ie' );
if ( /MSIE 10\.\d+;/.test( navigator.userAgent ) ) {
@gyrus
gyrus / wp-override-image-sizes
Created February 19, 2015 21:32
Override WordPress image sizes defined in admin
<?php
add_filter( 'option_thumbnail_size_w', function() { return 176; } );
add_filter( 'option_thumbnail_size_h', function() { return 210; } );
add_filter( 'option_thumbnail_crop', function() { return 1; } );
add_filter( 'option_medium_size_w', function() { return 400; } );
add_filter( 'option_medium_size_h', function() { return 265; } );
add_filter( 'option_medium_crop', function() { return 1; } );
add_filter( 'option_large_size_w', function() { return 746; } );
add_filter( 'option_large_size_h', function() { return 372; } );
@gyrus
gyrus / pilau-list-dimensions.js
Created August 9, 2014 20:18
Use jQuery to calculate the heights of each row in a list, and the total number of rows (even if the list items are floated)
/**
* For a list, calculate how many rows, height of each row
*
* @param {object} l The list jQuery object
* @return {object}
*/
function pilau_list_dimensions( l ) {
var d = {
@gyrus
gyrus / pilau-multiply-posts.php
Last active August 29, 2015 14:04
Allows the artificial multiplication of posts in WordPress queries for testing purposes.
<?php
/**
* Allow the multiplication of posts in query results for testing purposes.
*
* In the query args, set pilau_multiply to the number you want the posts multiplying by.
* NOTE: If using get_posts() instead of WP_Query, you will need to set suppress_filters to true.
*/
add_filter( 'the_posts', 'pilau_multiply_posts', 10, 2 );
function pilau_multiply_posts( $posts, $query ) {
@gyrus
gyrus / get-video-thumbnail.php
Created September 10, 2013 19:49
Get the URL of a thumbnail for a video on a 3rd-party service
<?php
/**
* Get the URL of a thumbnail for a video on a 3rd-party service
*
* @param string $url Currently supports YouTube and Vimeo
* @return string
*/
function pilau_get_video_thumbnail( $url ) {
$thumb_url = null;
@gyrus
gyrus / slideshow.js
Last active December 22, 2015 18:29
A class to manage a simple slideshow with jQuery.
/**
* Slideshow
*/
( function( $ ) {
$.PilauSlideShow = function( options ) {
/** The slideshow wrapper element */
this.el = options.el;
ul {
padding-left: 1.5em;
li {
list-style: none;
&:before {
content: '\2022';
color: @color-green;
display: block;
position: relative;
max-width: 0;
@gyrus
gyrus / sharethis-icons.php
Created July 1, 2013 11:03
Social media icons for use with ShareThis plugin, including flag to distinguish between "global" sharing of site and individual page sharing.
/**
* Output social media icons
*
* @param bool $global Global style?
* @return void
*/
function pilau_share_icons( $global = false ) {
$url = '';
if ( $global ) {
$url = ' st_url="' . home_url() . '"';
@gyrus
gyrus / breadcrumbs.php
Created June 18, 2013 22:47
WordPress breadcrumbs output
/**
* Output breadcrumbs
*
* A lot of options for formatting, but this just uses the <nav> element, plus the
* 'breadcrumb' class as per @link http://microformats.org/wiki/blog-post-formats
*
* @uses $post
* @uses is_404()
* @uses apply_filters()
* @uses pilau_breadcrumb_link()