Skip to content

Instantly share code, notes, and snippets.

@aaronsummers
aaronsummers / responsive-image.html
Last active Mar 23, 2021
Responsive background image script
View responsive-image.html
<!--
Each image is added to a new data attribute large, medium and small.
Add the image url followed by a space and then the width to apply the image.
Finally so the js can call the images add the responsive-bg class.
-->
<div class="elab_responsive-bg "
data-large="/images/hero-1440x360.jpg 1024"
data-medium="/images/hero-768x360.jpg 768"
@aaronsummers
aaronsummers / reset-acf-metabox.php
Last active Mar 19, 2021 — forked from electricbrick/reset-acf-metabox.php
Reset ACF Metabox Positions
View reset-acf-metabox.php
<?php
$user_id = 1;
$custom_post_type = 'my_post_type';
function prefix_reset_metabox_positions(){
delete_user_meta( $user_id, 'meta-box-order_post' ); // Posts
delete_user_meta( $user_id, 'meta-box-order_page' ); // Pages
delete_user_meta( $user_id, 'meta-box-order_' . $custom_post_type ); // Custom post types
}
add_action( 'admin_init', 'prefix_reset_metabox_positions' );
@aaronsummers
aaronsummers / wp-post_status-change.SQL
Created Mar 9, 2021 — forked from micjamking/wp-post_status-change.SQL
Bulk update ALL WordPress post statuses in SQL
View wp-post_status-change.SQL
# Change post_type value if targeting 'page' or a custom post type
# Change ALL posts status from 'publish' to 'draft'
UPDATE wp_posts SET post_status = 'publish' WHERE (post_type = 'post' and post_status = 'draft')
View page-scroll.js
const body = document.body;
const scrollUp = "scroll-up";
const scrollDown = "scroll-down";
let lastScroll = 0;
window.addEventListener("scroll", () => {
const currentScroll = window.pageYOffset;
if (currentScroll <= 0) {
body.classList.remove(scrollUp);
return;
@aaronsummers
aaronsummers / mutation-observer.js
Created Feb 5, 2021
waypoint - scroll into view - mutation observer
View mutation-observer.js
// https://usefulangle.com/post/113/javascript-detecting-element-visible-during-scroll
var observer = new IntersectionObserver(function(entries) {
const body = document.body;
const scrollUp = "scroll-up";
const scrollDown = "scroll-down";
// isIntersecting is true when element and viewport are overlapping
// isIntersecting is false when element and viewport don't overlap
if(entries[0].isIntersecting === true) {
body.classList.add(scrollDown);
@aaronsummers
aaronsummers / custom-walker.php
Created Jan 15, 2021
Custom walker with nav icon ( presuming the nav icon is an SVG using file_get_contents() )
View custom-walker.php
<?php
// In your functions.php
class Menu_Icon_Walker extends Walker_Nav_Menu {
function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent\n";
@aaronsummers
aaronsummers / mailhog-mamp.md
Created Nov 5, 2020 — forked from jaredatch/mailhog-mamp.md
Install MailHog with MAMP Pro
View mailhog-mamp.md

Install MailHog with MAMP Pro, using HomeBrew.

MailHog

First let's make sure HB is updated. Open up terminal for the following steps.

$ brew update
@aaronsummers
aaronsummers / Remove .DS_Store from GIT repository.md
Last active Oct 1, 2020
Remove .DS_Store from GIT repository
View Remove .DS_Store from GIT repository.md
@aaronsummers
aaronsummers / browser-back-button-fire-js.js
Created Aug 12, 2020
watch for back button page loads
View browser-back-button-fire-js.js
/*
https://stackoverflow.com/questions/37838430/detect-if-page-is-load-from-back-button#answer-53317159
*/
/* CHROME */
if (window.performance) {
var navEntries = window.performance.getEntriesByType('navigation');
if (navEntries.length > 0 && navEntries[0].type === 'back_forward') {
console.log('As per API lv2, this page is load from back/forward');
} else if (window.performance.navigation