Skip to content

Instantly share code, notes, and snippets.

View elliottmangham's full-sized avatar
🤓

Elliott Mangham elliottmangham

🤓
View GitHub Profile
@elliottmangham
elliottmangham / index.html
Created July 18, 2022 11:20
Clear Safari in-built cache (solves previous/back button issues when using LocomotiveScroll)
<!-- Add the following before </head> -->
<script>
( function () {
window.onpageshow = function( event ) {
if ( event.persisted ) {
window.location.reload();
}
};
} )();
</script>
/**
* Include responsive image
* @param array $aImageScope The image settings
* @param array $aClasses Apply classes to the image (optional)
* API Reference: https://ewww.io/exactdn-api/
* @example:
* $aImage = [
* 'image_url' => 'https://assets.imgix.net/examples/treefrog.jpg',
* 'alt' => 'Alternative text',
* 'picture_tag' => true,
@elliottmangham
elliottmangham / fnGravityFormSpinner.css
Last active May 12, 2021 14:13 — forked from vegaskev/functions.php
Change Gravity Forms Spinner to CSS Spinner
/* Spinner */
.gform_ajax_spinner {
margin-left: 20px;
border: 4px solid rgba(255, 255, 255, 0.3);
border-left: 4px solid rgba(110, 73, 217, 0.7);
animation: spinner 1.1s infinite linear;
border-radius: 50%;
width: 30px;
height: 30px;
}
@elliottmangham
elliottmangham / whitelistip.php
Created May 7, 2021 11:39
WPMU Defender: Whitelist IPs
// Use if member is locked out by Defender (add to /wp-content/mu-plugins/
add_filter( 'ip_lockout_default_whitelist_ip', function ( $ips ) {
$ip = 'YOUR IP HERE';
$ips[] = $ip;
return $ips;
} );
@elliottmangham
elliottmangham / PreserveGetParamaters.js
Created March 18, 2021 06:14
Prepend all anchors with preserved GET parameters
/**************
* Prepend all anchors with preserved GET parameters
**************/
( function() {
var domainsToDecorate = [
'domain1.com', // add or remove domains (without https or trailing slash)
'domain2.net'
],
queryParams = [
@elliottmangham
elliottmangham / fnRealWindowHeight.js
Created December 7, 2020 09:08
JS / Utilities / Force menu pop-up to be 100vh (to get around Chrome/iOS bar)
/**************
* Force menu pop-up to be 100vh (to get around Chrome/iOS bar)
**************/
$( window ).on( 'load', fnRealWindowHeight );
$( window ).on( 'resize', fnRealWindowHeight );
// Test.......
$( window ).on( 'load resize', fnRealWindowHeight );
function fnRealWindowHeight() {
@elliottmangham
elliottmangham / fnAccordions.js
Last active April 8, 2022 11:59
JS / Utilities / Accordions
function cAccordions( i, oComp ) {
var oComp = $( oComp );
var oAccordions = $( '.c_accordion', oComp );
/***************
* Accordions
***************/
$( '.accordion_head', oAccordions ).on( 'click', function() {
@elliottmangham
elliottmangham / fnCustomWordPressTableCol.php
Created December 7, 2020 08:52
WordPress / Add fields to admin columns
function fnCustomAwardEditTableCol( $aColumns ) {
$aColumns = [
'cb' => '<input type="checkbox" />',
'title' => 'Title',
'certificate' => 'Certificate',
'award_body' => 'Awarding Body'
];
return $aColumns;
@elliottmangham
elliottmangham / woo_auto_add_product_to_cart.php
Created December 7, 2020 08:49
WordPress / WooCommerce / Automatically add product to the cart
/******************************************************************************/
/* Automatically adding the product to the cart.
/* https://www.tychesoftwares.com/how-to-automatically-add-a-product-to-your-woocommerce-cart-in-3-different-scenarios/
/******************************************************************************/
function auto_add_product_to_cart() {
if ( ! is_admin() ) {
$product_id = 2623; // Product ID which will get added to cart. Should be dynamic.
@elliottmangham
elliottmangham / window.matchMedia.js
Last active July 6, 2021 15:33
JS / Utilities / window.matchMedia (media queries)
if (matchMedia) {
const mq = window.matchMedia("(min-width: 800px)");
mq.addListener(WidthChange);
WidthChange(mq);
}
// media query change
function WidthChange(mq) {
if (mq.matches) {
console.log( 'window width is at least 800px' );