Skip to content

Instantly share code, notes, and snippets.

View westcoastdigital's full-sized avatar

Jon Mather westcoastdigital

View GitHub Profile
@westcoastdigital
westcoastdigital / woocommerce-featured-product-loop.php
Created May 26, 2017 02:36
Custom loop args gro WooCommerce featured products
@westcoastdigital
westcoastdigital / functions.php
Created July 20, 2017 00:26
Table Creation and writing non working on live site
<?php
/*
* Create Saved Orders Custom Table
*/
function woo_create_saved_orders_data_table() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$table_name = $wpdb->prefix . 'woocommerce_saved_orders';
@westcoastdigital
westcoastdigital / functions.php
Created September 5, 2017 12:21
Custom copyright in GeneratePress whilst still allowing the customiser control to be used
<?php
// Add this to your functions.php of your child theme
function generatepress_custom_copyright() {
$copyrightCustomizer = get_theme_mod('generate_copyright');
if ( !empty($copyrightCustomizer) ) {
$date = date('Y');
$copyrightCustomizer = str_replace( '%current_year%', $date, $copyrightCustomizer );
$copyright = str_replace( '%copy%', '&copy;', $copyrightCustomizer );
// change this to what you want after the copyright
@westcoastdigital
westcoastdigital / Timed Christmas Announcement
Created December 13, 2017 06:56
Adds a banner to the top of GP page that shows up for Christmas every year
function jm_xmas_announcement() {
$xmascta = '<div class="xmas-announcement" style="background:#e6092a;text-align:center;padding:10px;">';
$xmascta .= '<a href="' . get_page_link(350) . '" style="color:white;text-transform:uppercase;">';
$xmascta .= '<p style="margin-bottom:0;padding:10px;border:1px solid white;">Now Taking Christmas Orders</p>';
$xmascta .= '</a>';
$xmascta .= '</div>';
$now = time();
$year = date('Y');
$promo = strtotime("01 November $year");
@westcoastdigital
westcoastdigital / version-enqueue.php
Last active December 14, 2017 00:23
Add version control to css for caching using time stamping
function jm_enqueue_scripts() {
// Gets the last time the style sheet was updated
$version = filemtime( get_stylesheet_directory() . '/style.css' );
// Enqueues style.css and assigns version to ensure browser cache is dropped
wp_enqueue_style( 'arbaros-styles', get_stylesheet_directory_uri() . '/style.css', array(), $version, 'all' );
}
add_action( 'wp_enqueue_scripts', 'jm_enqueue_scripts' );
@westcoastdigital
westcoastdigital / admin-css-conditional-hide.php
Created January 12, 2018 01:04
Hide sections in admin based on user
function wcd_hide_admin_sections() {
$user = wp_get_current_user();
$access = 'admin'; // this is your username that gets access
if($user && isset($user->user_login) && $access != $user->user_login) { ?>
<style>
li#toplevel_page_edit-post_type-acf-field-group,
li#menu-appearance,
li#menu-plugins,
li#menu-users,
li#menu-settings,
@westcoastdigital
westcoastdigital / if_slug_exisits.php
Created February 17, 2018 13:13
use function to detect if slug exists in WP databas
<?php
/*
* Use the function if ( the_slug_exists( '404' ) ) {} to detect if is in database
*/
function the_slug_exists($post_name)
{
global $wpdb;
if($wpdb->get_row("SELECT post_name FROM wp_posts WHERE post_name = '" . $post_name . "'", 'ARRAY_A')) {
return true;
@westcoastdigital
westcoastdigital / cpt-template.php
Created February 22, 2018 00:13
Include a CPT single template within plugin
<?php
/**
* Just place your CPT template in the root directory of the plugin eg: single-portfolio.php
* This function allows it to be overridden via a child theme etc
*/
function tammy_portfolio_template( $template ) {
global $post;
$post_type = 'portfolio'; // change post type name here if required
@westcoastdigital
westcoastdigital / jquery-img-svg.js
Created April 13, 2018 07:11
Output svg code when using img tag for better styling
$( 'img.svg' ).each( function() {
var $img = jQuery( this ),
imgID = $img.attr( 'id' ),
imgClass = $img.attr( 'class' ),
imgURL = $img.attr( 'src' );
$.get( imgURL, function( data ) {
// Get the SVG tag, ignore the rest
var $svg = jQuery( data ).find( 'svg' );
@westcoastdigital
westcoastdigital / seasalt.php
Created May 3, 2018 10:35
fix iodine issue
<?php
function iodine_is_active() {
if ( !class_exists('Iodine_Plugin') ) {
?>
<div class="notice notice-error is-dismissible">
<p>
<a target="_blank"
href="https://github.com/saltnpixels/Iodine"> <?php _e( 'This theme works best with iodine installed!!', 'digipress' ); ?></a>
</p>