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 November 2, 2016 18:29
Add Page number to the WordPress page title for SEO benefits
function my_blog_number_title($titletag) {
if( is_paged() ) {
global $wp_query;
$pagenum = $wp_query->query_vars['paged'];
$new_title = $titletag.' Page '.$pagenum;
$titletag = str_replace($titletag, $new_title ,$titletag);
return $titletag;
}
}
add_filter('wp_render_title_tag_filter','custom_wp_render_title_tag');
@gareth-gillman
gareth-gillman / functions.php
Created December 21, 2016 16:02
Show only shop managers to a shop manager in WP Admin users
add_action('pre_user_query','yoursite_pre_user_query');
function yoursite_pre_user_query($user_search) {
$roles = wp_get_current_user();
if ( in_array( 'shop_manager', (array) $roles->roles ) ) {
global $wpdb;
$user_search->query_where =
str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.ID IN (
SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
WHERE {$wpdb->usermeta}.meta_key = '{$wpdb->prefix}capabilities'
@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 / pe-customize-controls.css
Created February 15, 2017 00:45 — forked from OriginalEXE/pe-customize-controls.css
Extending WordPress Customizer Panels and Sections to allow nesting
.in-sub-panel #customize-theme-controls .customize-pane-child.current-panel-parent,
#customize-theme-controls .customize-pane-child.current-section-parent {
-webkit-transform: translateX(-100%);
-ms-transform: translateX(-100%);
transform: translateX(-100%);
}
@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
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 / 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';
}
@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
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 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' );