Skip to content

Instantly share code, notes, and snippets.

View lukecav's full-sized avatar
Translucent form radiates

Luke Cavanagh lukecav

Translucent form radiates
View GitHub Profile
@lukecav
lukecav / .htaccess
Created December 11, 2020 21:47
Smush Pro plugin WebP conversions rules for .htacess for Apache
# BEGIN SMUSH-WEBP
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/wp-content/smush-webp/disable_smush_webp !-f
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{DOCUMENT_ROOT}/wp-content/smush-webp/$1.$2.webp -f
RewriteRule ^/?(.+)\.(jpe?g|png)$ /wp-content/smush-webp/$1.$2.webp [NC,T=image/webp,E=WEBP_image]
</IfModule>
@lukecav
lukecav / functions.php
Last active April 3, 2024 23:20
Logout of WordPress without confirmation message
function getLogoutUrl($redirectUrl = ''){
if(!$redirectUrl) $redirectUrl = site_url();
$return = str_replace("&amp;", '&', wp_logout_url($redirectUrl));
return $return;
}
/**
* Bypass logout confirmation on nonce verification failure
*/
function logout_without_confirmation($action, $result){
@lukecav
lukecav / DNS Prefetch domains
Last active March 30, 2024 20:53
WP Rocket - Advanced Options Prefetch DNS requests examples
//maps.googleapis.com
//maps.gstatic.com
//fonts.googleapis.com
//fonts.gstatic.com
//ajax.googleapis.com
//apis.google.com
//google-analytics.com
//www.google-analytics.com
//ssl.google-analytics.com
//youtube.com
@lukecav
lukecav / add-to-cart.php
Last active March 25, 2024 06:59
Display Product Variations in the Shop Loop - With Conditional Apply Filter Logic
<?php
/**
* Custom Loop Add to Cart.
*
* Template with quantity and ajax.
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
global $product;
@lukecav
lukecav / wp-config.php
Created September 28, 2016 21:29
wp-config.php define Caching and Gzip
/* WordPress Cache */
define( 'WP_CACHE', true );
/* Compression */
define( 'COMPRESS_CSS', true );
define( 'COMPRESS_SCRIPTS', true );
define( 'CONCATENATE_SCRIPTS', true );
define( 'ENFORCE_GZIP', true );
/* Memory limit */
@lukecav
lukecav / functions.php
Created November 24, 2021 18:54
Disable Stripe scripts from loading on product and cart pages in WooCommerce
add_filter( ‘wc_stripe_load_scripts_on_product_page_when_prbs_disabled’, ‘__return_false’ );
add_filter( ‘wc_stripe_load_scripts_on_cart_page_when_prbs_disabled’, ‘__return_false’ );
@lukecav
lukecav / Queries
Created June 30, 2023 20:52
Delete Action Scheduler actions with a status of failed and canceled and truncate the Action Scheduler logs database table
DELETE FROMwp_actionscheduler_actions WHERE status IN ('failed','canceled')
TRUNCATE wp_actionscheduler_logs
@lukecav
lukecav / wp-config.php
Created October 25, 2021 16:39
Exclude options data from being caching in Redis using the Redis Object Cache plugin
define( 'WP_REDIS_IGNORED_GROUPS', [ 'options' ]);
@lukecav
lukecav / Commands
Last active February 20, 2024 09:41
WP-CLI commands to update WordPress core to version 6.4.3
# Delete the core updater lock option
wp option delete core_updater.lock
# Update WordPress to 6.4.3 forcefully
wp core update --version=6.4.3 --force
# Display the WordPress version
wp core version
# Checks for WordPress updates via Version Check API.
@lukecav
lukecav / functions.php
Created August 14, 2018 13:50
Enable revisions on products in WooCommerce
add_filter( 'woocommerce_register_post_type_product', 'wc_modify_product_post_type' );
function wc_modify_product_post_type( $args ) {
$args['supports'][] = 'revisions';
return $args;
}