Skip to content

Instantly share code, notes, and snippets.

View tommaitland's full-sized avatar

Tom Maitland tommaitland

  • Raisely
  • Melbourne, Australia
  • 00:31 (UTC +10:00)
View GitHub Profile
@tommaitland
tommaitland / form.html
Last active January 1, 2024 09:55
A form with every HTML form element (up to HTML5) for styling.
<form action="/">
<legend>A Sample Form Legend</legend>
<label for="name">Name: </label>
<input type="text" value="Name" name="Name" />
<label for="email">Email: </label>
<input type="email" value="Email" name="Email" />
@tommaitland
tommaitland / rotate.js
Created June 26, 2013 07:02
Really basic jQuery rotator
// Settings
var wrapper = '.testimonials'; // the element wrapping the rotator
var child = 'blockquote'; // the element to be rotated
// Rotate Script
$(wrapper).each( function() {
$(this).append('<a href="#" class="next button inner">Next Testimonial</a>');
$(this).find(child).each( function() {
@tommaitland
tommaitland / wp-custom-image-sizes.php
Last active June 23, 2017 14:26
Add custom images sizes to WordPress media uploader.
<?php
// Add to functions.php
function custom_image_sizes() {
add_theme_support('post-thumbnails');
add_image_size('banner', 960, 355, true);
add_image_size('thumb', 120, 120, true);
add_image_size('widget', 170, 400, false);
}
@tommaitland
tommaitland / functions.php
Created July 15, 2013 05:34
Remove post columns from WordPress SEO by Yoast
<?php
// functions.php
add_filter( 'wpseo_use_page_analysis', '__return_false' );
@tommaitland
tommaitland / carousel-options.js
Last active December 20, 2015 12:29
How to use Carousel - http://carousel.io
<?php
$gallery = get_children( 'posts_per_page=5&post_type=attachment&post_mime_type=image&post_parent=' . $post->ID );
$attr = array(
'class' => "attachment-$size wp-post-image",
);
foreach( $gallery as $image ) {
echo '<a href="' . wp_get_attachment_url($image->ID) . '" rel="gallery-' . get_the_ID() . '">';
echo wp_get_attachment_image($image->ID, 'thumbnail', false, $attr);
echo '</a>';
}
@tommaitland
tommaitland / ng-debounce.js
Last active November 9, 2018 02:17
Debounce/Throttling Directive for Angular JS 1.2+
angular.module('app', []).directive('ngDebounce', function($timeout) {
return {
restrict: 'A',
require: 'ngModel',
priority: 99,
link: function(scope, elm, attr, ngModelCtrl) {
if (attr.type === 'radio' || attr.type === 'checkbox') return;
elm.unbind('input');
@tommaitland
tommaitland / list-subpages.php
Last active December 31, 2015 11:39
Basic subpage listing in WordPress
<?php
// List subpages on parent and child page. Outputs ul > li.
$child_of = ($post->post_parent > 0) ? $post->post_parent : $post->ID;
if ($child_of > 0 && is_page()) {
wp_list_pages('title_li=&child_of='.$child_of);
}
@tommaitland
tommaitland / get-first-image.php
Created December 17, 2013 07:55
WordPress helper function that retrieves the first image from a post, with basic support for swapping the image size.
<?php
/*
Based on the original CSS-Tricks code (http://css-tricks.com/snippets/wordpress/get-the-first-image-from-a-post/)
## Usage
Include in functions.php
<?php echo get_first_image('thumbnail'); ?>
@tommaitland
tommaitland / bulk-resize.php
Created December 24, 2013 03:02
A very crude WordPress plugin to search through imported content and replace full size images with a resized counterpart.
<?php
/*
Plugin Name: Bulk Attachment Resize
Description: Destructive operations on DB to replace full images with their resized version.
Author: Agency
Version: 1.0.0
Author URI: http://agency.sc
*/