Skip to content

Instantly share code, notes, and snippets.

View gareth-gillman's full-sized avatar

gareth-gillman

View GitHub Profile
@gareth-gillman
gareth-gillman / functions.php
Created March 22, 2018 09:54
Yoast SEO change number of sitemap indexes
function max_entries_per_sitemap() {
return 5000;
}
add_filter( 'wpseo_sitemap_entries_per_page', 'max_entries_per_sitemap' );
@gareth-gillman
gareth-gillman / functions.php
Created March 21, 2018 18:30
Round Woocommerce Subtotal to the next integer
function gg_round_subtotal( $cart_subtotal; ) {
$cart_subtotal; = round( $cart_subtotal );
return $cart_subtotal;
}
add_action( 'woocommerce_before_calculate_totals', 'gg_round_subtotal', 10, 1);
@gareth-gillman
gareth-gillman / functions.php
Created March 20, 2018 23:44
Custom Array Validation for Contact Form 7
function gg_validation_filter( $result, $tag ) {
if ( 'your-name' == $tag[name] ) {
$items = array( '00','01','02' );
$post_item = $_POST['your-name'];
if( !in_array( $post_item, $items ) ) {
$result->invalidate( $tag, "This is not a valid zip!" );
}
@gareth-gillman
gareth-gillman / functions.php
Created March 15, 2018 13:02
Google Analytics WordPress
function gg_add_ga() {
echo '<script>';
echo '// ga code here';
echo '</script>';
}
add_action( 'wp_head', 'gg_add_ga' );
add_action( 'wp_footer', 'gg_add_ga' );
@gareth-gillman
gareth-gillman / functions;php
Created March 12, 2018 09:51
WordPress search only posts when viewing posts
function gg_postssearch($query) {
if( is_single( 'post' ) || is_post_type_archive( 'post' ) {
if( $query->is_search ) {
$query->set( 'post_type', 'post' );
}
return $query;
}
}
add_filter( 'pre_get_posts',' gg_postssearch' );
@gareth-gillman
gareth-gillman / functions.php
Created March 11, 2018 21:02
Count and Echo number of variations for a product
<?php
global $woocommerce, $product;
$variation_count = count( $product->get_available_variations() );
echo $variation_count;
?>
@gareth-gillman
gareth-gillman / functions.php
Created March 8, 2018 17:46
WordPress Preconnect Google Fonts
function gg_gfonts_prefetch() {
echo '<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>';
echo '<link rel="preconnect" href="https://fonts.googleapis.com/" crossorigin>';
}
add_action( 'wp_head', 'gg_gfonts_prefetch' );
@gareth-gillman
gareth-gillman / functions.php
Last active March 6, 2018 02:16
add content before Woocommerce Upsells
add_action( 'woocommerce_after_single_product_summary', 'gg_custom_before_upsells', '12 );
function gg_custom_before_upsells() {
echo 'something here';
}
function product_desc_shortcode( $post_excerpt )
{
$price = do_shortcode( '[my_shortcode]' );
return $price;
return $content;
}
add_filter('woocommerce_short_description', 'product_desc_shortcode', 10, 1);
@gareth-gillman
gareth-gillman / 0_reuse_code.js
Created September 26, 2017 06:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console