Instantly share code, notes, and snippets.

View dropdownmove.js
// if the sub-navigation is off-screen we want to bump it left
const parentsli = document.querySelectorAll( 'ul > li.page_item_has_children' );
for ( let parent of parentsli ) {
const children = parent.querySelector( 'ul.children' );
parent.addEventListener( 'mouseenter', evt => {
// compare with width, to dropdown offset, to width of drop down
const windowWidth = document.documentElement.clientWidth;
View google-query-calendar.php
<?php
require_once ('/Google/autoload.php'); // see https://github.com/google/google-api-php-client
require_once ('/Google/Service/Calendar.php');
$client = new Google_Client();
// $client settings and auth
$service = new Google_Service_Calendar($client);
$calendarId = 'username@gmail.com';
$optParams = array(
View functions.php
/**
* Home Page Slideshow: add meta box to home page
*/
add_action( 'add_meta_boxes', function () {
if (get_the_ID() !== intval(get_option('page_on_front'))) {
return;
}
add_meta_box(
'homepage_slideshow',
'Home Page SlideShow',
View wp-pass-php-into-js-alt.php
<?php
wp_scripts()->add_data(
'my_js_theme',
'my_theme_data',
sprintf(
'var my_theme_data = %s;',
wp_json_encode( [
'nonce' => wp_create_nonce( 'wp_rest' ),
'path' => $path,
'blogname' => get_option( 'blogname' ),
View wp-pass-php-into-js.php
<?php
add_action( 'wp_enqueue_scripts', function () {
wp_enqueue_script(
'my_js_theme',
get_template_directory_uri() . '/my_app.js?=' . time(),
false,
'',
true
);
View section-sticky-buttons.css
#events {
overflow: hidden;
position: relative;
}
#events .show {
width: 30.3%;
background: white;
float: left;
padding: 150px 0;
margin: 20px 1.5%;
View wp-image-filters.php
<?php
// Images in post content and galleries
add_filter( 'get_post_galleries', 'myplugin_filter_image_url', 999999 );
add_filter( 'widget_media_image_instance', 'myplugin_filter_image_url', 999999 );
// Core image retrieval
add_filter( 'image_downsize', 'myplugin_filter_image_url', 10, 3 );
// Responsive image srcset substitution
View wp-fix-tax-query.php
<?php
global $wp_taxonomies;
switch_to_blog($new);
if(!taxonomy_exists('my_missing_tax'))
$wp_taxonomies['my_missing_tax'] = 'delete';
// do `tax_query`'s in $new with `my_missing_tax`
View alfred-change-dev-pro.php
<?php // don't actually use the php in workflow
// get the result of Apple Script action
$url = '{query}';
$a = ['http:','.loc']; // dev
$b = ['https:','.com']; // production
// identify if production and invert if so
if (strstr($url,$b[1]))
View get_browser_url.as
tell application "System Events"
set myApp to name of first application process whose frontmost is true
if myApp is "Google Chrome" then
tell application "Google Chrome" to return URL of active tab of front window
else if myApp is "Opera" then
tell application "Opera" to return URL of front document
else if myApp is "Safari" then
tell application "Safari" to return URL of front document
else if myApp is "Firefox" then
tell application "System Events"