Jake Paris

Tagged: snippet

Debounce an input using select hook in WordPress/Gutenberg

I was building a component for the block editor which accepts user input (i.e. a text search) and searches for matching posts. For various reasons I couldn’t use the <URLInput> component and needed to roll something more custom. I got stuck on this because when using the useSelect hook triggered by changes from a text […]

SASS Mixins

Animations @mixin keyframes($name) { @-ms-keyframes #{$name} { @content } @-o-keyframes #{$name} { @content } @-moz-keyframes #{$name} { @content } @-webkit-keyframes #{$name} { @content } @keyframes #{$name} { @content } } @mixin animation($val) { -ms-animation: $val; -o-animation: $val; -webkit-animation: $val; -moz-animation: $val; animation: $val; } Example @include animation(( delay: .8s, duration: 1.6s, iteration-count: 1, name: fadeFromHilite, […]

Tags —

Fade-in text: jQuery plugin

This is a basic plugin for jQuery which adds an effect for slowly fading in text. There may be other plugins out there that have similar functionality, but this was an attempt to try building such a thing. Demo The Code

GET Query Params with Javascript

Update April 2018 Sigh, the things we learn as we go… This is actually way easier than I made it before. In fact, it’s so easy it doesn’t really need these wrapper functions around the URLSearchParams() family of things. However in the interest of making a transition from the earlier code, here you are: var […]

Shortcode to Use a WordPress widget in Page Content

A small snippet creating a shortcode which will display any widget.

Helper function (in vanilla js) to find a GET query parameter

var parseQueryParameters = function(){ var queryString = window.location.search; var queries = {}; if(queryString==”) return queries; var q = queryString.replace(‘?’,”).split(‘&’); q.forEach(function(pair){ var a = pair.split(‘=’); if(typeof a[1]===’undefined’) a.push(”); queries[a[0]] = a[1]; }); return queries; }; var getQueryStringValue = function(param){ var queries = parseQueryParameters(); if(typeof queries[param] == ‘undefined’) return false; else return queries[param]; };

Using AJAX in WordPress

Most of the work of setting up an ajax action in the WordPress environment happens in php-land. The PHP File Register & enqueue your script. In this example, I’ll assume the script has already been registered. wp_enqueue_script( ‘myscript’ ); *I’ve had trouble when I’ve tried to enqueue the script at the wp_enqueue_scripts action and added […]