Skip to content

Instantly share code, notes, and snippets.

View LucaRosaldi's full-sized avatar

Luca Rosaldi LucaRosaldi

View GitHub Profile
@LucaRosaldi
LucaRosaldi / iubenda_gtm.js
Created July 14, 2022 09:41
JS: Iubenda GTM integration callback
/* Copy this code in "Advanced Options" > "Callbacks > "onPreferenceExpressedOrNotNeeded" textarea */
/* See full explanation on: https://www.iubenda.com/en/help/1235-google-tag-manager-blocking-cookies */
function(preference){dataLayer.push({iubenda_ccpa_opted_out:_iub.cs.api.isCcpaOptedOut()});if(!preference){dataLayer.push({event:"iubenda_preference_not_needed"})}else{if(preference.consent===true){dataLayer.push({event:"iubenda_consent_given"})}else if(preference.consent===false){dataLayer.push({event:"iubenda_consent_rejected"})}else if(preference.purposes){for(var purposeId in preference.purposes){if(preference.purposes[purposeId]){dataLayer.push({event:"iubenda_consent_given_purpose_"+purposeId})}}}}}
@LucaRosaldi
LucaRosaldi / wp_extend_search_results_including_tags.php
Last active April 28, 2022 10:12
WP: extend search results including tags
<?php
/**
* Extend search results query including tags.
*
* @hook posts_where, posts_join, posts_groupby
*
* @param string
* @return string
*/
function my_theme_search_where_clause_include_tags( string $where ) : string
@LucaRosaldi
LucaRosaldi / wp_add_custom_image_sizes.php
Created April 6, 2022 08:00
WP: add custom image sizes
<?php
/**
* Add custom image sizes.
*
* @hook after_setup_theme
*
* @return void
*/
function my_theme_add_custom_image_sizes() : void
@LucaRosaldi
LucaRosaldi / container-queries.css
Last active January 7, 2022 10:13
CSS: Container Queries
.widget-name {
container: inline-size / widget-name;
/* Shorthand for: */
/* container-type: inline-size; */
/* container-name: widget-name; */
/* For quick testing, do this to get a resize handle on desktop: */
/* resize: both; */
/* overflow: hidden; */
}
@LucaRosaldi
LucaRosaldi / reset.css
Last active December 17, 2022 07:05
CSS: Modern Reset
/* -------------------------------------------*/
/* RESET
/* -------------------------------------------*/
*, *::before, *::after {
box-sizing: border-box;
}
* {
margin: 0;
}
@LucaRosaldi
LucaRosaldi / system-fonts.css
Last active June 21, 2022 15:50
CSS: System fonts
/* Sans Serif */
html, body {
font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif;
}
/* Serif */
html, body {
font-family: Iowan Old Style, Apple Garamond, Baskerville, Times New Roman, Droid Serif, Times, Source Serif Pro, serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;
}
@LucaRosaldi
LucaRosaldi / input-numeric.html
Created May 5, 2021 06:28
HTML: Better altenative to input type="number"
<!-- https://technology.blog.gov.uk/2020/02/24/why-the-gov-uk-design-system-team-changed-the-input-type-for-numbers/ -->
<input type="text" inputmode="numeric" pattern="[0-9]*">
@LucaRosaldi
LucaRosaldi / console-debug-overflow.js
Last active February 24, 2022 10:15
JS: Paste in console to show elements which overflow the viewport horizontally.
/* Paste this snippet in the console */
var docWidth = document.documentElement.offsetWidth;
[].forEach.call(
document.querySelectorAll('*'),
function(el) {
if (el.offsetWidth > docWidth) {
console.log(el);
}
}
@LucaRosaldi
LucaRosaldi / sql_woocommerce_get_customers.mysql
Last active February 24, 2022 10:17
WordPress, WooCommerce, MySQL: Get list of customers with at least one order placed (for email marketing)
SELECT wp_users.user_email as "Email", firstmeta.meta_value AS "First Name", lastmeta.meta_value AS "Last Name", ordermeta.meta_value AS "Orders Placed" FROM wp_users
LEFT JOIN wp_usermeta as firstmeta on wp_users.ID = firstmeta.user_id and firstmeta.meta_key = 'first_name'
LEFT JOIN wp_usermeta as lastmeta on wp_users.ID = lastmeta.user_id and lastmeta.meta_key = 'last_name'
LEFT JOIN wp_usermeta as ordermeta on wp_users.ID = ordermeta.user_id and ordermeta.meta_key = '_order_count'
WHERE wp_users.ID IN (
SELECT user_id FROM wp_usermeta WHERE meta_key = '_order_count' AND meta_value > 0
)
@LucaRosaldi
LucaRosaldi / touch-query.css
Created March 12, 2020 09:01
CSS: Media Query for touch and non-touch devices
@media (hover: hover) {
/* targets only non-touch devices */
}
@media (hover: none) {
/* targets only touch devices */
}