Skip to content

Instantly share code, notes, and snippets.

View linkdigitaluk's full-sized avatar

Link Digital UK linkdigitaluk

View GitHub Profile
@linkdigitaluk
linkdigitaluk / .htaccess
Last active February 20, 2020 13:38
[Leverage Browser Caching / Expire Headers] Improve Page Speed Ranking #wordpress #pagespeed #htaccess
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/js "access plus 1 month"
@linkdigitaluk
linkdigitaluk / wp-config.php
Last active August 2, 2019 08:45
[WordPress debug constant] WP_DEBUG options to enable and log errors but not show on the front-end #wordpress #wpconfig #php
/** WP Debug Settings */
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define( 'WP_DEBUG_DISPLAY', false );
@linkdigitaluk
linkdigitaluk / functions.php
Last active August 6, 2019 07:04
[Autopopulate image data (WP)] Autopopulate the Alt, Title and Description fields, using the image name, when uploading an image through WordPress #WordPress #A11y
/** Set alt, title and description for image uploads */
function set_image_meta_upload( $post_ID ) {
if ( wp_attachment_is_image( $post_ID ) ) {
$my_image_title = get_post( $post_ID )->post_title;
$my_image_title = preg_replace( '%\s*[-_\s]+\s*%', ' ',
$my_image_title );
$my_image_title = ucwords( strtolower( $my_image_title ) );
$my_image_meta = array(
'ID' => $post_ID,
'post_title' => $my_image_title,
@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 = {
@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 / 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 / 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 / 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 / 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 / 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>
}
?>