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 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 / header.php
Created February 9, 2017 18:03
Add logo to Twenty Seventeen Menu
<?php
/**
* The header for our theme
*
* This is the template that displays all of the <head> section and everything up until <div id="content">
*
* @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
*
* @package WordPress
* @subpackage Twenty_Seventeen
@gareth-gillman
gareth-gillman / functions.php
Created April 10, 2019 18:44
get product price
// Add Shortcode
function gg_price_shortcode( $atts ) {
$product = wc_get_product( $post_id );
echo $product->get_price_html();
}
add_shortcode( 'product-price', 'gg_price_shortcode' );
@gareth-gillman
gareth-gillman / functions.php
Created February 5, 2019 16:28
Woo Checkout Spam
function wcs_checkout_field( $checkout ) {
woocommerce_form_field(
'wcs_buyer_gift',
array(
'type' => 'text',
'class' => array('wcs-field form-row-wide'),
),
$checkout->get_value( 'wcs_buyer_gift' )
);
}
@gareth-gillman
gareth-gillman / functions.php
Created August 19, 2018 19:02
WordPress create page on user register
function gg_new_user_page( $user_id ) {
$user_info = get_userdata( $user_id );
$user_login = $user_info->user_login;
$newpage = array(
'post_title' => wp_strip_all_tags( $user_login ),
'post_type' => 'page',
'post_content' => '',
'post_status' => 'publish',
//'page_template' => 'template-blog.php'
<?php
$server_date = get_date();
$date = strtotime( $server_date );
$hour = date('H', $date);
if( $hour > 9 && $hour < 20 ) {
echo 'it's between 9am and 8pm';
}
@gareth-gillman
gareth-gillman / functions.php
Created July 13, 2018 21:56
WordPress Hide admin elements
function prefix_admin_hide_contents() {
$admin_user = wp_get_current_user();
if( $admin_user->ID != '5' ) {
echo '<style>';
echo '.element { display: none; }';
echo '</style>';
}
}
add_filter( 'admin_head', 'prefix_admin_hide_contents' );
@gareth-gillman
gareth-gillman / functions.php
Last active July 5, 2018 00:38
Hide columns based on user role
function my_manage_columns( $columns ) {
$user = wp_get_current_user();
if ( in_array( 'author', 'editor', (array) $user->roles ) ) {
unset($columns['column-name']);
return $columns;
}
}
function my_column_init() {
add_filter( 'manage_posts_columns' , 'my_manage_columns' );
@gareth-gillman
gareth-gillman / functions.php
Created June 11, 2018 21:17
add button to woocommerce category
function gg_cat_btn() {
if( is_tax( 'product_cat' ) ) {
add_action( 'woocommerce_after_shop_loop_item_title', 'gg_readmore_btn' );
}
}
add_filter( 'woocommerce_after_shop_loop_item', 'gg_cat_btn' );
function gg_readmore_btn() {
echo '<a class="cat-btn" href="'.get_permalink().'">'.__( 'Book / Get quote!', 'your-plugin' ).'</a>';
}
function set_compression( $compression ) {
return 100;
}
add_filter( 'jpeg_quality', 'set_compression', 999 );
add_filter( 'wp_editor_set_quality', 'set_compression', 999 )