Skip to content

Instantly share code, notes, and snippets.

View 2aces's full-sized avatar

2ACES 2aces

View GitHub Profile
@2aces
2aces / ao-language-switcher-alt-commented.js
Last active February 27, 2018 23:17
Autoptimize / Optimize Matters website language switcher
// includes polyfill https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
Array.prototype.includes||Object.defineProperty(Array.prototype,"includes",{value:function(r,e){if(null==this)throw new TypeError('"this" is null or not defined');var t=Object(this),n=t.length>>>0;if(0===n)return!1;var i,o,a=0|e,u=Math.max(a>=0?a:n-Math.abs(a),0);for(;u<n;){if((i=t[u])===(o=r)||"number"==typeof i&&"number"==typeof o&&isNaN(i)&&isNaN(o))return!0;u++}return!1}});
(function() {
var httpRequest;
var location = window.location.href;
var suffix = '';
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = getCountry;
httpRequest.open('GET', 'https://freegeoip.net/json/', true);
@2aces
2aces / futta-gutenprint.php
Created February 6, 2018 21:55
Frank Goossens (Futta) function to extract blocks from WP Gutenberg (Proof of Concept) as https://blog.futtta.be/2018/01/25/how-to-extract-blocks-from-gutenberg/
// proof-of-concept to extract all WordPress Gutenberg's blocks as array
// author: Frank Goossens (Futta)
// source: https://blog.futtta.be/2018/01/25/how-to-extract-blocks-from-gutenberg/
add_action('the_content','gutenprint',10,1);
function gutenprint($html) {
// check if we need to and can load the Gutenberg PEG parser
if ( !class_exists("Gutenberg_PEG_Parser") && file_exists(WP_PLUGIN_DIR."/gutenberg/lib/load.php") ) {
include_once(WP_PLUGIN_DIR."/gutenberg/lib/load.php");
}
@2aces
2aces / clock-with-js-canvas.html
Created January 21, 2018 23:14
Javascript and HTML5 Canvas clock
// taken from http://completewebdevelopercourse.com/content/10-html5css3/11.5.html
<canvas id="clock" width="500" height="500">
Please upgrade your browser.
</canvas>
@2aces
2aces / wp-social-buttons-cloner.php
Created November 8, 2017 14:46
An experiment for cloning social buttons and insert them elsewhere in a WordPress page
function wp_social_buttons_cloner_scripts() {
wp_register_script( 'wp_social_buttons_cloner', $path_to_the_javascript_script, array(''), '0.1.0', true);
wp_register_script( 'wp_social_buttons_cloner');
};
add_action('wp_enqueue_scripts', 'wp_social_buttons_cloner_scripts');
@2aces
2aces / .htaccess-faux-comentarios-multilinhas
Last active October 11, 2017 19:41
Faux Multiline Comments on Apache / Faux Comentários Multilinhas no Apache. More on https://www.celsobessa.com.br/2017/10/11/hack-apache-faux-multiline-comments/
<FilesMatch "index-sbrubles123land9897BrazilQueerMuseum\.(php?)$">
#conteúdo e diretivas comentadas ficam aqui
</FilesMatch>
@2aces
2aces / add_noscript_filter-pt_br.php
Last active March 3, 2019 12:25
filters an enqueued script tag on WordPress (identified by the $handle variable) and adds a noscript element after it. If there is also an inline script enqueued after $handled, adds the noscript element after it.
/**
* @summary filtra uma tag de script na fila e adiciona um elemento noscript após ela
*
* @description filtra uma tag de script na fila (identificada pela variável $handle) e adiciona
* um elemento noscript após ela. Se também houver um script inline após o script
* identificado por $handle, adiciona o elemento noscript após ele.
*
* @access público
* @param string $tag A string da tag enviada pelo filtro `script_loader_tag` em WP_Scripts::do_item
* @param string $handle O nome (handle) do como enviado pelo filtro `script_loader_tag` em WP_Scripts::do_item
@2aces
2aces / conditional-remove-custom-css-archive.php
Created September 18, 2017 20:28
WordPress: remove custom CSS created by Customizer
// first check if we are not in Admin area
if( !is_admin ){
// check if we are in an archive
if( is_archive() ){
//remove wp_custom_css_cb from the actions queue on wp_head using the same priority, 101
remove_action('wp_head', 'wp_custom_css_cb', 101);
}
}
@2aces
2aces / conditional-remove-custom-css-archive-pt_br.php
Last active September 18, 2017 20:31
WordPress: removendo o CSS personalizado criado pelo Customizer
// primeiro verifica se não estamos no Admin
if( !is_admin ){
// detecta se estamos num arquivo
if( is_archive() ){
//remove a função wp_custom_css_cb da lista de ações em wp_head usando a mesma prioridade 101
remove_action('wp_head', 'wp_custom_css_cb', 101);
}
}
@2aces
2aces / primary_category.php
Created September 8, 2017 22:16 — forked from jawinn/primary_category.php
Display Primary Category (Yoast's WordPress SEO)
<?php
// SHOW YOAST PRIMARY CATEGORY, OR FIRST CATEGORY
$category = get_the_category();
$useCatLink = true;
// If post has a category assigned.
if ($category){
$category_display = '';
$category_link = '';
if ( class_exists('WPSEO_Primary_Term') )
@2aces
2aces / is_tree_extended.php
Last active July 17, 2017 23:14
An extended version of WordPress is_tree and is_page conditionals for finding if a page is child or grandchild of another page by it's slug
/**
* is_tree extended function.
*
* Extends the typical is_tree function -- as found in WordPress Theme Handbook ( https://developer.wordpress.org/themes/basics/conditional-tags/ ) and CSS Tricks ( https://css-tricks.com/snippets/wordpress/if-page-is-parent-or-child/ ) -- and allows it to find if a page is child or grandchild of another page by it's slug
*
* @access public
* @author Celso Bessa <celso.bessa@2aces.com.br>
* @see https://www.celsobessa.com.br/2017/07/17/is-tree-conditional-extended/
* @param mixed $page
* @param bool $use_slug if set to true, (default: false)