Skip to content

Instantly share code, notes, and snippets.

View robin-scott's full-sized avatar
🏠
Working from home

Rob Scott robin-scott

🏠
Working from home
View GitHub Profile
@robin-scott
robin-scott / functions.php
Last active July 2, 2018 20:18
Hide woocommerce related products
// place this in your child theme functions.php file to remove related products from WooCommerce
// posted by Robin Scott of Silicon Dales, here: https://silicondales.com/tutorials/woocommerce/remove-related-products-woocommerce/
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
@robin-scott
robin-scott / funtions.php
Created September 3, 2018 10:43
Declare WooCommerce Support in theme (simple)
// Below declares woocommerce support when added to a theme or child theme functions.php - from the official WooCommerce Github (August 2018)
// Posted by Robin Scott of Silicon Dales here https://silicondales.com/tutorials/woocommerce/declare-woocommerce-support-theme/ to benefit the Open Source community. Free to share and distribute for any purpose.
function mytheme_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'mytheme_add_woocommerce_support' );
@robin-scott
robin-scott / funtions.php
Created September 3, 2018 10:45
Declare WooCommerce Support (With settings)
// Originally posted in official WooCommerce Github
// Re-posted by Robin Scott of Silicon Dales here https://silicondales.com/tutorials/woocommerce/declare-woocommerce-support-theme/ to aid understanding and benefit all in the Open Source community. Feel free to share are distribute as required!
function mytheme_add_woocommerce_support() {
add_theme_support( 'woocommerce', array(
'thumbnail_image_width' => 150,
'single_image_width' => 300,
'product_grid' => array(
'default_rows' => 3,
'min_rows' => 2,
// Add this into your .htaccess file at the root of your WordPress installation. By Robin Scott of Silicon Dales.
// See full details here: https://silicondales.com/tutorials/wordpress/lock-out-all-traffic-except-your-ip-from-login-admin/
<Files wp-login.php>
Order Deny,Allow
Deny from all
Allow from X.X.X.X
</Files>
// Add this to an .htaccess file at the top of the wp-admin directory to lock down this section of your site to only trusted IP addresses
// By Robin Scott of Silicon Dales - details here: https://silicondales.com/tutorials/wordpress/lock-out-all-traffic-except-your-ip-from-login-admin/
Order Deny,Allow
Deny from all
Allow from X.X.X.X
@robin-scott
robin-scott / htaccess
Created October 19, 2018 08:37
Deny access to wp-admin BUT allow ajax to be used in WordPress
// Add this to an .htaccess file at the top of the wp-admin directory to lock down this section of your site to only trusted IP addresses - BUT still allow ajax access
// By Robin Scott of Silicon Dales - details here: https://silicondales.com/tutorials/wordpress/lock-out-all-traffic-except-your-ip-from-login-admin/
<Files admin-ajax.php>
Order allow,deny
Allow from all
Satisfy any
</Files>
Order Deny,Allow
Deny from all
@robin-scott
robin-scott / functions.php
Last active November 21, 2018 14:05
WooCommerce - Add extra weight to all cart items in a specific shipping class - Find out more here -> https://silicondales.com/tutorials/woocommerce/add-additional-shipping-weight-to-cart-items-in-a-shipping-class/
// By Robin Scott of Silicon Dales
// Add 6oz extra weight to all cart items in specific shipping class
// More information here: https://silicondales.com/tutorials/woocommerce/add-additional-shipping-weight-to-cart-items-in-a-shipping-class/
add_action( 'woocommerce_before_calculate_totals', 'rscott_add_custom_weight', 10, 1);
function rscott_add_custom_weight( $cart_object ) {
if ( (is_admin() && ! defined( 'DOING_AJAX' ) ) || $cart_object->is_empty() )
return;
if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
return;
$additionalweight = 6;
Order Deny,Allow
Deny from 222.222.222.222
update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');
## EXPIRES CACHING - by Robin Scott of Silicon Dales, here https://silicondales.com/tutorials/seo/leverage-browser-caching-images-css-js/##
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/x-javascript "access 1 month"