Skip to content

Instantly share code, notes, and snippets.

View donaldallen's full-sized avatar

Donald Allen donaldallen

View GitHub Profile
<?php
// My rewrite
$our_thinking_structure = 'our-thinking/%category%/%postname%';
$wp_rewrite->add_permastruct('our_thinking', $our_thinking_structure, false);
// Going to /our-thinking/scenarios/a-spirit-of-entrepreneurship/ works just fine.
// But going to /our-thinking/scenarios/ tries to load an archive page.
// Can I get it to load the page I have set in WP instead?
$leader_structure = '/performance/leaders/%leader%';
$wp_rewrite->add_rewrite_tag("%leader%", '([^/]+)', "leader=");
$wp_rewrite->add_permastruct('leader', $leader_structure, false);
// Works
http://test.dev/?leader=from-basement-startup-to-global-force#more-118
// Doesn't work
http://test.dev/performance/leaders/from-basement-startup-to-global-force
@donaldallen
donaldallen / gist:7666810
Created November 26, 2013 21:44
Using HTML5's article for blog previews.
<article role="article" itemscope itemtype="http://schema.org/BlogPosting">
<img src="someimage.jpg">
<header>
<h5><a href="#">TedX Edmonton Story (21pt)</a></h5>
<p><time itemprop="dateCreated" datetime="2013-10-12">Wednesday, October 12, 2013</time></p>
</header>
<p>15/24pt Velit auctor aliquet. Aenean sollicitudin, lorem quis bibendum auctor, nisi elit consequat ipsum, nec sagittis sem nibh id elit. Duis sed odio sit amet nibh vulputate cursus a sit amet mauris. Morbi accumsan ipsum velit. Nam nec tellus a odio tincidunt auctor a ornare odio himenaeos.</p>
@donaldallen
donaldallen / gist:7377151
Created November 8, 2013 20:31
The mobile version of your responsive page likely doesn't need jQuery. Use zepto.js instead. Lots of the same functionality without all the cruft.
<?php
if (wp_is_mobile()) {
wp_deregister_script('jquery');
wp_register_script('zepto-js', JS_PUBLIC_URI . 'vendor/zepto/zepto.min.js', array(), '', false);
wp_enqueue_script('zepto-js');
}
@donaldallen
donaldallen / gist:7361132
Created November 7, 2013 20:16
Put quotes in <article>s inside a <figure> as <blockquote>, and use <figcaption> for the caption.
<figure class="quote">
<blockquote>
Measuring programming progress by lines of code is like measuring aircraft building progress by weight.
</blockquote>
<figcaption>Bill Gates</figcaption>
</figure>
@donaldallen
donaldallen / gist:7341222
Created November 6, 2013 18:14
Need to perform the same task when the DOM is ready and when the browser is resized?
$(document).ready(function() {
$(window).resize(function() {
// Do your thing
}).trigger('resize');
});
@donaldallen
donaldallen / gist:7270942
Created November 1, 2013 19:51
Nice little odometer-ish function.
var current_odometer_top = 0;
if ($('ul.odometer')) {
$('ul.odometer').animate({ top:0 }, 500, function() {
window.setInterval(function() {
odometer();
}, 3000);
});
$('ul.odometer li:nth-child(1)').addClass('active');
}
@donaldallen
donaldallen / gist:6828916
Last active December 24, 2015 16:29
Easy-to-use Ziptastic API.
<?
$client = new Guzzle\Http\Client('http://zip.elevenbasetwo.com/v2');
$response = $client->get('CA/T8N7L6')->send();
if ($response->isSuccessful()) {
$data = $response->json();
echo sprintf('City: %s<br>State: %s<br>Country: %s', $data['city'], $data['state'], $data['country']);
} else {
return false;
}
@donaldallen
donaldallen / gist:6781589
Created October 1, 2013 16:52
Get last JSON error.
<?php
private function check_json()
{
switch (json_last_error()) {
case JSON_ERROR_DEPTH:
$messages['error']['json'] = 'Maximum stack depth exceeded.';
break;
case JSON_ERROR_STATE_MISMATCH:
$messages['error']['json'] = 'Underflow or the modes mismatch.';
<?php
add_action('template_redirect', function() {
$url = $_SERVER['REQUEST_URI'];
if (strstr($url, '/wp-admin/downloads/communications')) {
// Do stuff
}
if (strstr($url, 'utm')) {