Skip to content

Instantly share code, notes, and snippets.

View ericvalois's full-sized avatar
🏠
Working from home

Eric Valois ericvalois

🏠
Working from home
View GitHub Profile
@ericvalois
ericvalois / index.html
Created February 5, 2021 12:48
CSS custom properties IE11 polyfill
<!-- load only on IE -->
<script>window.MSInputMethodContext && document.documentMode && document.write('<script src="https://cdn.jsdelivr.net/gh/nuxodin/ie11CustomProperties@4.1.0/ie11CustomProperties.min.js"><\/script>');</script>
@ericvalois
ericvalois / editor.js
Created February 3, 2021 15:04
Simple WordPress Gutenberg editor script
// add inline styles to some blocks
wp.domReady = function() {
const setExtraPropsToBlockType = (props, blockType, attributes) => {
const notDefined = (typeof props.className === 'undefined' || !props.className) ? true : false
if (blockType.name === 'core/heading') {
return Object.assign(props, {
style: 'line-height: 1; font-size: 24px; font-weight: 700; margin-top: 0; margin-bottom: 25px;',
});
@ericvalois
ericvalois / functions.php
Created May 28, 2020 14:32
Remove WordPress responsive image markups (sizes, srcset) for SVG images
/*
* Remove wordpress responsive image markup for SVG
*/
add_filter( 'wp_calculate_image_sizes', 'remove_svgt_responsive_image_attr', 10, 3 );
function remove_svgt_responsive_image_attr( string $sizes, array $size, $image_src = null ) {
$explode = explode( '.', $image_src );
$image_type = end( $explode );
if( $image_type === "svg" ){
@ericvalois
ericvalois / html-page.html
Created January 14, 2018 19:20
Show page load time snippet.
<script>
window.onload = function(){
setTimeout(function(){
window.performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {};
var t = performance.timing || {};
if (!t) {
return;
}
@ericvalois
ericvalois / functions.php
Created October 5, 2017 12:17
WordPress: Move Scripts and Stylesheet to footer
add_action('wp_print_styles', function() {
if ( ! doing_action( 'wp_head' ) ) { // ensure we are on head
return;
}
global $wp_scripts, $wp_styles;
// save actual queued scripts and styles
$queued_scripts = $wp_scripts->queue;
$queued_styles = $wp_styles->queue;
// empty the scripts and styles queue
$wp_scripts->queue = array();
@ericvalois
ericvalois / ajax-no-jquery.js
Last active March 17, 2017 18:16
Basic WordPress Rest API Ajax Request
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = ajaxDone;
httpRequest.open('GET', '/url/endpoint/');
httpRequest.send();
function ajaxDone() {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
// We got the `httpRequest.responseText`!
}
@ericvalois
ericvalois / gruntfile.js
Created October 26, 2016 12:25
WordPress stylesheet versionning
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// running `grunt sass` will compile once
sass: {
development: {
options: {
sourcemap: "none",
@ericvalois
ericvalois / functions.php
Last active October 14, 2024 08:57
Add Fancy Toggle Switch On/Off for Advanced Custom Field (ACF) - True or False ACF Type
/**
* ACF Custom Switch True or False
* Design Inspiration: http://www.w3schools.com/howto/howto_css_switch.asp
*/
add_action('admin_head', 'perf_custom_switch');
function perf_custom_switch() {
echo '<style>
.switch {
position: relative;
display: inline-block !important;
@ericvalois
ericvalois / query.sql
Last active April 8, 2016 16:51
MySQL helper
# Delete a particular meta
DELETE FROM wp_postmeta WHERE wp_postmeta.meta_key = '_upsell_ids';
DELETE FROM wp_postmeta WHERE wp_postmeta.meta_key = '_crosssell_ids';
# Delete all orpheline meta
DELETE wp_postmeta FROM wp_postmeta
WHERE NOT EXISTS (
SELECT * FROM wp_posts
WHERE wp_postmeta.post_id = wp_posts.ID
)