This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* WordPress: Remove unwanted image sizes. | |
* Remove the three sizes medium_large, 1536x1536, 2048x2048 | |
* Not needed for 99% of Woocommerce stores | |
*/ | |
add_filter('intermediate_image_sizes', function($sizes) { | |
return array_diff($sizes, ['medium_large']); // Medium Large (768 x 0) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A fix for the horribly slow WordPress post and product editor | |
// With many thanks to Jon Brown | |
// Read about it at https://9seeds.com/wordpress-admin-post-editor-performance/ | |
/** | |
* Remove Ancient Custom Fields metabox from post editor | |
* because it uses a very slow query meta_key sort query | |
* so on sites with large postmeta tables it is super slow | |
* and is rarely useful anymore on any site | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This fixes the Google Pagespeed Insights warning for "Properly Size Images" | |
// First inspect your gallery thumbnails with chrome developer tools and find the size they are RENDERED at on DESKTOP | |
// In my case they render at exactly 165 x 110 | |
// This function creates the correct gallery thumbnail size for Woocommerce and does NOT affect any image sizes of Flatsome | |
// After adding this function (use Code Snippets plugin) You need to Regenerate Thumbnails | |
// Use the plugin "Renegrate thumbmnails" with the setting "Skip regenerating existing correctly sized thumbnails (faster)." | |
add_filter( 'woocommerce_get_image_size_gallery_thumbnail', function( $size ) { | |
return array( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*----------------------------------------------------------------------------*/ | |
// redirects for login / logout / registration | |
/*----------------------------------------------------------------------------*/ | |
// Redirect after login | |
add_filter('woocommerce_login_redirect', 'login_redirect'); | |
function login_redirect($redirect_to) { | |
return home_url(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
# Proxmox or other server kernel params cheap tune and secure. | |
# Try it if you have heavy load on server - network or memory / disk. | |
# No harm assumed but keep your eyes open. | |
# | |
# @updated: 2020-02-06 - more params used, adjust some params values, more comments on params | |
# | |
### NETWORK ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Passive event listeners | |
// Add this to your own custom.js file < YOU NEED TO CREATE THIS FILE YOURSELF | |
// Call the file in your body using | |
// <script src="https://mydomain.com/wp-content/themes/my-child-theme/inc/js/custom.js" ></script> | |
jQuery.event.special.touchstart={setup:function( _, ns, handle ){this.addEventListener("touchstart", handle, { passive: !ns.includes("noPreventDefault") });}}; | |
jQuery.event.special.touchmove={setup:function( _, ns, handle ){this.addEventListener("touchmove", handle, { passive: !ns.includes("noPreventDefault") });}}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Remove "nofollow" from add to cart / Select options buttons | |
* What possessed Woocommerce to inplement this we shall never know ? | |
*/ | |
add_filter( 'woocommerce_loop_add_to_cart_args', 'add_to_cart_args_remove_nofollow' ); | |
function add_to_cart_args_remove_nofollow( $args ) { | |
unset($args['attributes']['rel']); | |
return $args; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Useful function to hide the product featured image for all products in specific categories | |
// The main image displayed when visiting products in these categories becomes the first gallery image | |
// Written by Mitchell Krog - mitchellkrog@gmail.com | |
// Replace categoryslug2 / categoryslug1 with your category slug (add to array as needed) | |
add_filter('woocommerce_single_product_image_thumbnail_html', 'remove_featured_image', 10, 2); | |
function remove_featured_image($html, $attachment_id ) { | |
global $product; | |
if( ! has_term( array( 'categoryslug1', 'categoryslug2' ) , 'product_cat', $product->get_id() ) ){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'get_terms', 'ts_get_subcategory_terms', 10, 3 ); | |
function ts_get_subcategory_terms( $terms, $taxonomies, $args ) { | |
$new_terms = array(); | |
// if it is a product category and on the shop page | |
if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() &&is_shop() || is_product_category()) { | |
foreach( $terms as $key => $term ) { | |
if ( !in_array( $term->slug, array( 'uncategorised','artist' ) ) ) { //pass the slug name here | |
$new_terms[] = $term; | |
}} | |
$terms = $new_terms; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# --------------------------------------------------------------------------- | |
# Generate WebP Images - Uses cwebp command line tool for Linux | |
# This will generate / re-generate all webp images for all JPG and PNG files | |
# Being command line based it is incredibly fast | |
# If you don't want to re-generate existing files set generateall=0 | |
# If you want to re-generate everything set generateall=1 | |
# USE this script at your own risk and Only if you know what you are doing | |
# Written by Mitchell Krog - mitchellkrog@gmail.com |