Skip to content

Instantly share code, notes, and snippets.

View linkdigitaluk's full-sized avatar

Link Digital UK linkdigitaluk

View GitHub Profile
@linkdigitaluk
linkdigitaluk / in-array-any.php
Created January 24, 2020 14:47
[Find multiple items within an array] Useful php array methods to check multiple values exist in an array #php #array
function in_array_any($needles, $haystack) {
return !empty(array_intersect($needles, $haystack));
}
@linkdigitaluk
linkdigitaluk / getDateTimeNow.js
Created December 13, 2019 11:31
[Get Current Date and Time - JavaScript] #javascript #date #time
function getDateTimeNow() {
var now = new Date();
return now.getDate() + '/' + (now.getMonth()+1) + '/' + now.getFullYear() + ' - ' + now.getHours() + ':' + now.getMinutes();
//returns "13/12/2019 - 11:26"
//NOTE: now.getMonth() is zero indexed (January is 0) so plus one to make it human friendly.
}
@linkdigitaluk
linkdigitaluk / ga-event.js
Last active March 15, 2020 22:55
[Fire Google Analytics Event] Code to fire an event in Google Analytics on click #google #analytics #jquery
/*
Google Analytics is required for the below to function
This code is ideally fired on anchor click.
It then passes the anchor link as well as a desired data-attribute on the anchor as the event label.
This has been tested with the gtag.js analytics code.
*/
function fireGoogleEvent(event) {
url = $(this).attr('href');
data = $(this).data('ATTRIBUTE');
@linkdigitaluk
linkdigitaluk / functions.php
Created September 23, 2019 09:37
[Console Log PHP Variable/Array] #WordPress #PHP
<?php function console($arr) {
<script type="text/javascript">
var arr = <?php echo json_encode($arr); ?>;
console.log(arr);
</script>
}
?>
@linkdigitaluk
linkdigitaluk / wp-show-hide.js
Created September 11, 2019 11:42
[WP Show/Hide] 'Show More / Less' implementation using WP's own more tag button -- needs comments.js to read comments #WP #Jquery #showmore
//Checking div for a shorcode and doing work to hide everything after it
//Set Some naming and labels
let wrapOptions = {
moreButtonText: 'Show More',
lessButtonText: 'Show Less',
buttonClass: 'readMoreButton',
wrapperClass: 'wrapAllText',
wrapperClosedClass: 'wrapAllText__hidden',
@linkdigitaluk
linkdigitaluk / woocommerce.php
Created September 4, 2019 14:48
[Custom Add to cart on shop/category page] #graveyard
function get_woo_variations() {
global $product;
return $product->get_available_variations();
}
add_action( 'woocommerce_after_shop_loop_item', 'amend_add_to_cart_buttons', 1 );
function amend_add_to_cart_buttons() {
if( is_product_category() || is_shop()) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
@linkdigitaluk
linkdigitaluk / gulpfile.babel.js
Created August 30, 2019 11:08
[WP Setup - gulp file] A Babel gulpfule that takes into account WooCommerce .scss from _s
/**
* Gulpfile.
*
* Gulp with WordPress.
*
* Implements:
* 1. Live reloads browser with BrowserSync.
* 2. CSS: Sass to CSS conversion, error catching, Autoprefixing, Sourcemaps,
* CSS minification, and Merge Media Queries.
* 3. JS: Concatenates & uglifies Vendor and Custom JS files.
@linkdigitaluk
linkdigitaluk / kitchen-sink.html
Created August 28, 2019 10:58
[HTML Kitchen Sink] Contains 99.999% of most html elements that we would need to style #html #kitchensink
<div id="wrapper">
<h1>This is the primary heading and there should only be one of these per page</h1>
<p>A small paragraph to <em>emphasis</em> and show <strong>important</strong> bits.</p>
<ul>
<li>This is a list item</li>
<li>So is this - there could be more</li>
<li>Make sure to style list items to:
<ul>
<li>Not forgetting child list items</li>
<li>Not forgetting child list items</li>
@linkdigitaluk
linkdigitaluk / package.json
Last active August 28, 2019 10:59
[WP Setup - package.json] A sample WP Gulp Package file if you want to bake one yourself. #wpGulp #NPM
{
"name": "[[ Project Name ]]",
"description": "A WPGulp based project.",
"version": "1.0.0",
"author": "Link Digital",
"repository": {
"type": "git",
"url": "[[ Git Repo ]]"
},
"license": "MIT",
@linkdigitaluk
linkdigitaluk / wpgulp.config.js
Last active May 14, 2021 13:01
[WP Setup - wpgulp config file] For setting Up WPGulp, make sure yourProject URL matches a virual host set up in Wordpress or you'll have a bad time #wpGulp #NPM
/**
* WPGulp Configuration File
*
* 1. Edit the variables as per your project requirements.
* 2. In paths you can add <<glob or array of globs>>.
*
* @package WPGulp
*/
module.exports = {