Skip to content

Instantly share code, notes, and snippets.

View astockwell's full-sized avatar

Alex Stockwell astockwell

View GitHub Profile
@astockwell
astockwell / gist:4157590
Created November 27, 2012 22:28
SASS Mixin: Background color alpha compatible with IE 6-9
@import "compass/css3/images";
// Partially via http://www.colorzilla.com/gradient-editor/
@mixin nav-child-bg-color-alpha($color, $alpha: 0.5) {
background: url(screen.css); // Point to this css file. Fix for IE "No Transparency Click" bug on <a> elements w/ bg transparency. Via http://haslayout.net/css/No-Transparency-Click-Bug
@include background-image(linear-gradient(top, rgba($color, $alpha) 0%,rgba($color, $alpha) 100%));
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#{ie-hex-str(rgba($color, $alpha))}', endColorstr='#{ie-hex-str(rgba($color, $alpha))}',GradientType=0 ); /* IE6-9 */
}
// USEAGE:
@astockwell
astockwell / gist:4177665
Created November 30, 2012 18:44
Wordpress: Google Analytics with "One wp-config.php file to rule them all"
<?php if (WP_ENV != 'local' && WP_ENV != 'staging') { ?>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
@astockwell
astockwell / script.js
Last active October 13, 2015 15:28
Detect if element exists on page in jQuery
if ($('.lt-ie8').is('*')) {
//code
}
@astockwell
astockwell / wp-config.php
Last active May 19, 2019 23:03
One wp-config.php file to rule them all (multiple environments)
// One wp-config.php file for multiple environments setup from http://www.messaliberty.com/2010/01/how-to-create-a-single-wp-config-file-for-local-and-remote-wordpress-development/
if ($_SERVER['REMOTE_ADDR']=='127.0.0.1' || $_SERVER['REMOTE_ADDR']=='localhost' || preg_match('/^192\.168\.5\./', $_SERVER['REMOTE_ADDR'])) {
define('WP_ENV', 'local');
} elseif ($_SERVER['HTTP_HOST']=='tld.stagingurl.com') {
define('WP_ENV', 'staging');
} else {
define('WP_ENV', 'production');
}
if ( WP_ENV == 'local' ) {
@astockwell
astockwell / search.php
Created January 4, 2013 21:34
Google Custom Search v2 Include Code for Wordpress - WORKING
<?php get_header(); ?>
<section>
<!-- Put the following javascript before the closing </head> tag. -->
<script>
(function() {
var cx = '000000000000000000000:aaa1aa1aa1a';
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
@astockwell
astockwell / loop.php
Last active December 14, 2015 11:38
Pristine Wordpress loop examples
<?php // Referencing http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts ?>
<?php
// EXAMPLE new WP_Query object
?>
<?php
// Query posts by new criteria.
$args = array(
'posts_per_page' => -1,
@astockwell
astockwell / cpt_tax.php
Last active December 16, 2015 13:59
Pristine Wordpress Custom Post Type (and Related Custom Taxonomy) Declaration
<?php
function xyz_create_cpt_animal() {
$label_singular = 'Animal';
$label_plural = $label_singular . 's';
$labels = array(
'name' => __($label_plural),
'singular_name' => __($label_singular),
'add_new' => __('Add New'),
@astockwell
astockwell / loop.php
Created May 2, 2013 22:59
WP_Query by meta_value first letter
<?php
$args = array(
'post_type' => 'faculty',
'meta_query' => array(
// 'relation' => 'AND',
// array(
// 'key' => 'online-extra-type',
// 'value' => 'Your Space',
// 'compare' => '='
// ),
@astockwell
astockwell / script.js
Last active December 17, 2015 18:09
Poor-man's Javascript performance timing, via http://kellegous.com/j/2013/01/26/layout-performance/
var Now;
if (typeof performance !== 'undefined' && performance.now) {
Now = function() {
return performance.now();
};
} else if (Date.now) {
Now = function() {
return Date.now();
};
} else {
@astockwell
astockwell / header.php
Created May 30, 2013 18:13
Creates edit post/page button in wordpress (only displays if user is logged in) so you can hide the terrible admin bar.
<!-- Place in "body > header" or equivalent -->
<?php edit_post_link( __('Edit'), '<span class="edit-link">', '</span>' ); ?>