Skip to content

Instantly share code, notes, and snippets.

View pagelab's full-sized avatar
🚀

Márcio Duarte pagelab

🚀
View GitHub Profile
@pagelab
pagelab / index.html
Created July 13, 2022 19:40
Example of block pattern created with the Editor Plus plugin
<!-- wp:group {"align":"wide","layout":{"inherit":true},"epCustomPaddingMobileModified":true,"epCustomPaddingMobile":{"value":{"top":"","right":"","bottom":"","left":""},"unit":"em","important":true},"epAnimationGeneratedClass":"edplus_anim-JUfwXp","epGeneratedClass":"eplus-wrapper"} -->
<div class="wp-block-group alignwide eplus-wrapper"><!-- wp:group {"style":{"spacing":{"blockGap":"0px"}},"layout":{"type":"flex","flexWrap":"nowrap"},"epCustomMargin":{"value":{"top":"","right":"","bottom":"2","left":""},"unit":"em","important":true},"epAnimationGeneratedClass":"edplus_anim-KaeqNy","epGeneratedClass":"eplus-wrapper"} -->
<div class="wp-block-group eplus-wrapper"><!-- wp:paragraph {"style":{"typography":{"lineHeight":"1"},"color":{"text":"#204a72"}},"fontSize":"x-large","epCustomPadding":{"value":{"top":"","right":"0.4","bottom":"","left":""},"unit":"em","important":false},"epCustomMargin":{"value":{"top":"","right":"0.4","bottom":"","left":""},"unit":"em","important":true},"epCustomBorder":{"borderTop":{},"b
@pagelab
pagelab / functions.php
Created June 2, 2017 17:42
WordPress: add defer and async to selected scripts via script_loader_tag
<?php
/**
*
* Add defer and async to selected scripts
*
* @author Matthew Horne
* @link https://matthewhorne.me/defer-async-wordpress-scripts/
*/
@pagelab
pagelab / widget-update-function.js
Created June 30, 2015 21:50
jQuery function for update events on WordPress widgets save/add
( function( $ ){
function initColorPicker( widget ) {
widget.find( '.color-picker' ).wpColorPicker( {
change: _.throttle( function() { // For Customizer
$(this).trigger( 'change' );
}, 3000 )
});
}
function onFormUpdate( event, widget ) {
@pagelab
pagelab / typewriter.html
Created January 31, 2022 17:57
Typewriter effect (CSS only)
<!DOCTYPE html>
<html>
<head>
<style>
.writer {
font-family: Courier, monospace;
display: inline-block;
}
.writer-text {
display: inline-block;
@pagelab
pagelab / functions.php
Created October 18, 2021 17:05
Enable Block Editor support for WooCommerce products
/**
* Enable Gutenberg support for WooCommerce Products
* @link https://github.com/woocommerce/woocommerce/issues/28419#issuecomment-945430144
*/
add_filter( 'use_block_editor_for_post_type', function ( $can_edit, $post_type ) {
if ( $post_type == 'product' ) {
$can_edit = true;
}
@pagelab
pagelab / dom.php
Created October 12, 2021 17:35
DOMDocument: como remover tags <style> de uma string com código HTML.
<?php
// Remover tags style do HTML.
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->loadHTML( $content );
$styles = $dom->getElementsByTagName( 'style' );
while( $styles->length > 0 ) {
$style = $styles->item(0);
@pagelab
pagelab / script.js
Created September 21, 2021 01:15
Validação de campo textarea utilizando o atributo pattern (não suportado nativamente).
// Validação dos campos para Javascript personalizado.
jQuery( '.epc-custom-js textarea' ).on( 'input change propertychange', function() {
var pattern = jQuery( this ).attr( 'pattern' );
// Define o padrão da expressão regular.
if ( typeof pattern !== typeof undefined && pattern !== false ) {
var patternRegex = new RegExp('^' + pattern.replace(/^\^|\$$/g, '') + '$', 'gm' );
hasError = ! jQuery( this ).val().match( patternRegex );
// Só apresenta a mensagem se o campo não estiver vazio.
@pagelab
pagelab / process.sh
Last active August 5, 2021 21:42
Codekit custom hook to process TXT files in a folder to form the theme.json for the WordPress site editor.
#!/bin/bash
rm -f -- "$CK_PROJECT_ROOT/theme.json" && cat "$CK_PROJECT_ROOT/src/json/"*.txt >> "$CK_PROJECT_ROOT/theme.json"
@pagelab
pagelab / script.js
Created February 8, 2021 17:51
Remove random itens on the WordPress Tag Cloud Widget.
(function ($) {
"use strict";
$(function () {
$( 'a.tag-cloud-link' ).each(function( index ) {
var index = Math.round( Math.random() * 1 );
$( this ).eq( index ).hide();
});
});
}(jQuery));
@pagelab
pagelab / IE11-grid-with-autoprefixer.md
Created October 31, 2018 18:34 — forked from pestbarn/IE11-grid-with-autoprefixer.md
CSS Grid for IE11 using Autoprefixer

About: CSS Grid for IE11

CSS Grid in IE11 is an implementation based on the 2011 spec, which means we aren't really able to use grids out of the box according to the newer spec. However, Autoprefixer automates a lot of work for us with getting the correct IE11 properties, and it has support for most (if not all?) -ms-grid properties.

There are still some gotchas which Autoprefixer can't help with though:

  • There is no auto-placement behaviour in the 2011 spec. This means that for IE11, you have to position everything. rather than use the autoplacement ability of grid.
  • Using minmax() with an auto value is not supported, and will break things - e.g. minmax(auto, 1200px) will not work. To use minmax, you have to specify two positive values - e.g. minmax(500px, 1200px).
  • grid-gap properties were added in a later spec. To create grid-gaps in IE11, you will need to create separate