Skip to content

Instantly share code, notes, and snippets.

View interactiveRob's full-sized avatar

Rob Kirkner interactiveRob

View GitHub Profile
@interactiveRob
interactiveRob / plainJS_get_query_string_params.js
Created May 24, 2019 13:38
Plain JS get query string parameters
/*———— -Handling query strings- ————*/
let getQueryString = function ( field, url ) {
var href = url ? url : window.location.href;
var reg = new RegExp( '[?&]' + field + '=([^&#]*)', 'i' );
var string = reg.exec(href);
return string ? string[1] : null;
};
let i = getQueryString('i');
@interactiveRob
interactiveRob / replace-space-percent-20.js
Created May 22, 2019 18:01
Quick javascript urlencode spaces as %20
$0.textContent.replace(/\s/g, '%20');
@interactiveRob
interactiveRob / async_defer_enqueue.php
Created May 2, 2019 15:49
Wordpress script enqueue with async and defer attributes
<?php
function enqueue_recaptcha_scripts() {
wp_enqueue_script( 'google-recaptcha', 'https://www.google.com/recaptcha/api.js', array(), '0.0.1', true );
}
add_action( 'wp_enqueue_scripts', 'enqueue_recaptcha_scripts' );
function add_async_defer_attributes($tag, $handle) {
if ( 'google-recaptcha' !== $handle )
return $tag;
return str_replace( ' src', ' async defer src', $tag );
@interactiveRob
interactiveRob / dynamicBrowserTabTitle.js
Created February 14, 2019 16:57
Change the text (title) on the browser tab when the user loses focus on the site (switches tabs)
import { isMobile , isMobileSize } from '../helpers/utilities';
import store from '@/modules/PubSub/store/index.js';
const BrowserTabs = (() => {
class BrowserTabs {
constructor() {
this.hidden = null;
this.visibilityChange = null;
this.store = store;
this.title = document.title;
@interactiveRob
interactiveRob / archive.php
Last active February 11, 2019 17:25
Basic WP_Query template for displaying a custom selection of posts per category
<?php
get_header();
$cat_id = get_queried_object_id();
$is_category = is_category($cat_id);
$query_cat_id = $is_category ? $cat_id : null;
$cat_data = get_category($cat_id);
$post_id = $is_category ? $cat_id : get_option('page_for_posts');
//means-- if it's a category, set the ID to that category page so we can get its title etc.
@interactiveRob
interactiveRob / copy-to-clipboard-es6.js
Last active October 6, 2021 10:09
Copy String to Clipboard ES6 Method
copyToClipboard(str) {
/* ——— Derived from: https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f
improved to add iOS device compatibility——— */
const el = document.createElement('textarea'); // Create a <textarea> element
let storeContentEditable = el.contentEditable;
let storeReadOnly = el.readOnly;
el.value = str; // Set its value to the string that you want copied
el.contentEditable = true;
@interactiveRob
interactiveRob / scss.json
Created January 22, 2019 19:15
VS Code Shortcut Snippet for include-media.scss
"Include Media Breakpoint": {
"prefix": "media",
"body": [
"@include media('${1|>=,<=,>,<|}${2|480px,768px,1024px,1170px|}') {",
"\t$0",
"}",
],
"description": "@include-media plugin sccs breakpoint"
},
@interactiveRob
interactiveRob / custom-dev-uploads-dir.php
Created January 20, 2019 01:46
Custom Wordpress uploads directory for dev-only files
<?php
$upload_dir = wp_upload_dir();
$custom_files_path = $upload_dir['baseurl'] . '/files/';
//...continued
?>
@interactiveRob
interactiveRob / plain-js-siblings-es6.js
Created January 18, 2019 20:03
Plain JS get siblings ES6 Method
getSiblings(elem) {
var siblings = [];
var sibling = elem.parentNode.firstChild;
for (; sibling; sibling = sibling.nextSibling) {
if (sibling.nodeType !== 1 || sibling === elem) continue;
siblings.push(sibling);
}
return siblings;
}
@interactiveRob
interactiveRob / page-some-template.php
Last active August 6, 2021 15:22
Standard Wordpress Page Template Boilerplate with required comment
<?php
/*Template Name: Some Template */
?>