Skip to content

Instantly share code, notes, and snippets.

Gray Ayer grayayer

Block or report user

Report or block grayayer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@grayayer
grayayer / gist:f939bf4f2be0d631dc51b066bf3b8e19
Last active Nov 30, 2018
wp-perf-optimization-without-plugin
View gist:f939bf4f2be0d631dc51b066bf3b8e19
/*Update following in your WordPress theme's functions.php file */
// Remove Query String from Static Resources
function remove_cssjs_ver( $src ) {
if( strpos( $src, '?ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 );
@grayayer
grayayer / add-product-to-cart.php
Created Mar 3, 2018 — forked from sc0ttkclark/add-product-to-cart.php
WooCommerce Automatically add product to cart on site visit
View add-product-to-cart.php
<?php
/*
* This code goes into theme functions.php or a custom plugin
*/
/**
* Add product to cart on page load
*/
function add_product_to_cart() {
@grayayer
grayayer / gist:4bd0ce48286969303cb6623c8c654cda
Created May 11, 2017
hide WP version from scripts and styles
View gist:4bd0ce48286969303cb6623c8c654cda
/* Hide WP version strings from scripts and styles
* @return {string} $src
* @filter script_loader_src
* @filter style_loader_src
*/
function fjarrett_remove_wp_version_strings( $src ) {
global $wp_version;
parse_str(parse_url($src, PHP_URL_QUERY), $query);
if ( !empty($query['ver']) && $query['ver'] === $wp_version ) {
$src = remove_query_arg('ver', $src);
@grayayer
grayayer / functions.php
Created Apr 20, 2017 — forked from temperatio/functions.php
Woocommerce: Remove related products
View functions.php
/**
* Remove related products
*/
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
@grayayer
grayayer / functions.php
Created Apr 20, 2017
remove related products from the bottom of product pages in Woocommerce
View functions.php
/* remove related products from the bottom of product pages in Woocommerce */
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
add_action( 'woocommerce_after_single_product_summary', 'related_upsell_products', 15 );
function related_upsell_products() {
global $product;
if ( isset( $product ) && is_product() ) {
View gist:82d3edcfdbf4774e394c7305aa98444a
/*WordPress has a built in function, the_meta(), for outputting all custom fields. But this function is limited in that it doesn't always output all of them. For example, it misses custom fields added by plugins which begin with an _ underscore.
This bit of code uses an alternate function, get_post_custom() which will return all of them, and display all values. Good for debugging.*/
<h3>All Post Meta</h3>
<?php $getPostCustom=get_post_custom(); // Get all the data ?>
<?php
foreach($getPostCustom as $name=>$value) {
@grayayer
grayayer / on-sale-woocommerce-sort.php
Created Nov 28, 2016
Order Products by ‘On Sale’ in WooCommerce
View on-sale-woocommerce-sort.php
add_filter( 'woocommerce_get_catalog_ordering_args', 'wcs_get_catalog_ordering_args' );
function wcs_get_catalog_ordering_args( $args ) {
$orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
if ( 'on_sale' == $orderby_value ) {
$args['orderby'] = 'meta_value_num';
$args['order'] = 'DESC';
$args['meta_key'] = '_sale_price';
@grayayer
grayayer / The7ChildThemeFunctions.php
Created Oct 26, 2016 — forked from thecodepoetry/functions.php
To change default pre selected sidebar position in The7 and Armada
View The7ChildThemeFunctions.php
function dt_change_default_sidebar() {
global $DT_META_BOXES;
if ( $DT_META_BOXES ) {
if ( isset($DT_META_BOXES[ 'dt_page_box-sidebar' ]) ) {
$DT_META_BOXES[ 'dt_page_box-sidebar' ]['fields'][0]['std'] = 'left'; // use disabled to disable sidebar
}
@grayayer
grayayer / plugin-name.php
Created Oct 10, 2016
Disable a plugin's check for updates - useful when you've modified the plugin directly (don't do that though)
View plugin-name.php
add_filter( 'http_request_args', 'dm_prevent_update_check', 10, 2 );
function dm_prevent_update_check( $r, $url ) {
if ( 0 === strpos( $url, 'http://api.wordpress.org/plugins/update-check/' ) ) {
$my_plugin = plugin_basename( __FILE__ );
$plugins = unserialize( $r['body']['plugins'] );
unset( $plugins->plugins[$my_plugin] );
unset( $plugins->active[array_search( $my_plugin, $plugins->active )] );
$r['body']['plugins'] = serialize( $plugins );
}
return $r;
@grayayer
grayayer / functions.php
Last active Oct 7, 2016 — forked from BFTrick/functions.php
Change WooCommerce Email Styles
View functions.php
<?php
add_filter( 'woocommerce_email_styles', 'patricks_woocommerce_email_styles' );
function patricks_woocommerce_email_styles( $css ) {
$css .= "#template_header { background-color: #231f20; }";
return $css;
}
You can’t perform that action at this time.