Skip to content

Instantly share code, notes, and snippets.

View chrisgoddard's full-sized avatar

Chris Goddard chrisgoddard

View GitHub Profile
@chrisgoddard
chrisgoddard / calltrackingmetrics-gaid-snippet
Last active August 29, 2015 14:04
Push Google Analytics clientId parameter to calltrackingmetrics.com platform
// paste this in footer - should be after Google Analytics and CallTrackingMetrics snippets.
var __ctm_cvars = __ctm_cvars || [];
ga(function(tracker) {
var MyID = tracker.get('clientId');
__ctm_cvars.push({gaid: MyID });
});
@chrisgoddard
chrisgoddard / wpexternalapi.php
Last active October 10, 2016 11:15
WordPress External API endpoint class
/*
WpExternalApi class use
$api = WpExternalApi::get('url-slug');
will create endpoint at www.example.com/url-slug/json and www.example.com/url-slug/xml
$api->set_logic(callback);
function callback($input){
@chrisgoddard
chrisgoddard / wp-utilities.php
Last active January 7, 2021 01:55
WordPress Utility Functions
<?php
/*
* @name: WordPress utility functions
* @desc: Useful utility functions for WordPress
* @author: https://github.com/chrisgoddard
*/
/*
Twitter
https://twitter.com/intent/tweet?text=$TITLE$&url=$URL$&via=$TWITTERHANDLE$
Facebook
http://www.facebook.com/sharer/sharer.php?u=$URL$
Google Plus
@chrisgoddard
chrisgoddard / load
Created June 19, 2015 16:53
Async Script Loader
(function(a,b,c,e,d){a=b.createElement(c);
b=b.getElementsByTagName(c)[0];
a.async=1;d&&(a.onload=d);a.src=e;b.parentNode.insertBefore(a,b)
})(window,document,"script","//example.com/script", function callback(){});
function getUrlParam(url, param) {
var match = url.match('(?:\\?|&)' + param + '=([^&#]*)');
return (match && match.length == 2) ? decodeURIComponent(match[1]) : '';
}
@chrisgoddard
chrisgoddard / find-overflow.js
Created October 12, 2015 22:48
Find unintended body overflow
var docWidth = document.documentElement.offsetWidth;
[].forEach.call(
document.querySelectorAll('*'),
function(el) {
if (el.offsetWidth > docWidth) {
console.log(el);
}
}
);
/**
* Simple regex/user agent mobile checker
* about 99% accurate when compared to 175k sessions in GA
*/
function isMobile()
{
return window.navigator.match(/Mobi|Touch|Opera\ Mini|Android/)
}
@chrisgoddard
chrisgoddard / json-ld-gtm.html
Last active July 23, 2023 16:52
JSON-LD GTM Tag
<script>
(function(){
var data = {
"@context": "http://schema.org",
"@type": "BlogPosting",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": {{Page URL}}
},
"headline": {{SCHEMA - Article Headline}},
@chrisgoddard
chrisgoddard / patterns
Created October 25, 2016 17:28
Useful regex patterns
Extract domain from string (with or without protocol)
[?:http(s)?:\/\/]?([a-z0-9\-]+\.?[a-z0-9\-]+\.[a-z]{2,3})