Skip to content

Instantly share code, notes, and snippets.

View chrisblakley's full-sized avatar
⚔️
Take that, entropy!

Chris Blakley chrisblakley

⚔️
Take that, entropy!
View GitHub Profile
@chrisblakley
chrisblakley / server-side-ga-events.php
Last active August 16, 2022 19:22
PHP functions to send data to Google Analytics
//Parse the GA Cookie
function gaParseCookie() {
if (isset($_COOKIE['_ga'])) {
list($version, $domainDepth, $cid1, $cid2) = explode('.', $_COOKIE["_ga"], 4);
$contents = array('version' => $version, 'domainDepth' => $domainDepth, 'cid' => $cid1 . '.' . $cid2);
$cid = $contents['cid'];
} else {
$cid = gaGenerateUUID();
}
return $cid;
@chrisblakley
chrisblakley / active_users_metabox.php
Last active February 12, 2022 10:11
Get data about active WordPress users on your site as well as list when they were last online.
<?php
/*==========================
This snippet shows how to add an active user count to the WordPress Dashboard.
Copy these contents to functions.php
===========================*/
//Active Users Metabox
add_action('wp_dashboard_setup', 'gearside_activeusers_metabox');
function gearside_activeusers_metabox(){
@chrisblakley
chrisblakley / trello_styles.css
Last active September 23, 2018 16:43
Custom CSS to enchance Trello.
/* Show the move cursor to demonstrate drag/drop scrolling on the interface. */
#board {
cursor: move;
}
#board .list {
cursor: default;
}
/* Change the background to a texture while maintaining board color. */
@chrisblakley
chrisblakley / admin_functions.php
Last active June 26, 2018 16:19
Business Hours Custom Field Group without ACF
<?php
//Add Open/Closed info to location listing columns
add_filter('manage_edit-location_columns', 'schc_location_hours_columns_head');
function schc_location_hours_columns_head($defaults){
$defaults['openclosed'] = 'Open/Closed';
return $defaults;
}
add_action('manage_location_posts_custom_column', 'schc_location_hours_columns_content', 15, 3);
function schc_location_hours_columns_content($column_name, $id){
if ( $column_name == 'openclosed' ){
@chrisblakley
chrisblakley / google-maps-js-api.php
Created April 13, 2017 16:35
A too in-depth implementation of Google Maps JS API
<script>
jQuery(document).on('ready', function(){
mapInfo = [];
mapActions();
jQuery.getScript('https://www.google.com/jsapi?key=' + nebula.site.options.nebula_google_browser_api_key, function(){
google.load('maps', '3', {
callback: function(){
getAllLocations();
}
@chrisblakley
chrisblakley / once.js
Created February 21, 2016 17:27
A function that allows other functions to be called only one time per page load.
function once(fn, args, unique){
if ( typeof onces === 'undefined' ){
onces = {};
}
if ( typeof fn === 'function' ){ //If the first parameter is a function
if ( typeof args === 'string' ){ //If no parameters
args = [];
unique = args;
}
@chrisblakley
chrisblakley / common_referral_spambots.txt
Last active November 6, 2016 23:33
Common referral spambots that appear in Google Analytics reports. More information on how to use this list: http://gearside.com/stop-spambots-like-semalt-buttons-website-darodar-others/
100dollars-seo.com
4webmasters.org
7makemoneyonline.com
aliexpress.com
anticrawler.org
best-seo-offer.com
best-seo-solution.com
bestwebsitesawards.com
blackhatworth.com
buttons-for-website.com
@chrisblakley
chrisblakley / example_json.js
Last active April 18, 2016 02:03
Cache Twitter feeds using PHP and JSON
//This can go in main.js or where ever.
jQuery.getJSON('/includes/twitter_cache.php', function(data) { //If using Nebula, the path will be: nebula.site.directory.stylesheet.uri + '/includes/twitter_cache.php'
jQuery.each(data, function(i) {
console.log(data[i]);
});
//Example full implementation:
jQuery('#tweetlink').attr('href', 'https://twitter.com/' + data[0].user.screen_name).text('@' + data[0].user.screen_name);
var tweetTime = new Date(Date.parse(data[0].created_at));
jQuery('#tweet').html(tweetLinks(data[0].text)).append(" <span class='twitter-posted-on'><i class='fa fa-clock-o'></i> " + timeAgo(tweetTime) + "</span>");
@chrisblakley
chrisblakley / pagespeed_detect.php
Last active February 11, 2016 23:45
Google Page Speed tracking
function gaParseCookie() {
if (isset($_COOKIE['_ga'])) {
list($version,$domainDepth, $cid1, $cid2) = explode('.', $_COOKIE["_ga"], 4);
$contents = array('version' => $version, 'domainDepth' => $domainDepth, 'cid' => $cid1 . '.' . $cid2);
$cid = $contents['cid'];
} else {
$cid = gaGenerateUUID();
}
return $cid;
}