Skip to content

Instantly share code, notes, and snippets.

@Anthodpnt
Anthodpnt / random-integer.js
Last active December 13, 2016 16:09
Math - Random Integer
/**
* This gist is for Javascript beginners.
* @author: Anthony Du Pont <[email protected]>
* @site: https://www.twitter.com/JsGists
*
* The `Math.random()` method only return a random number between 0 and 1.
* But what if you want a larger range than [0, 1] ? We need to improve this
* random method.
*
* Example:
@Anthodpnt
Anthodpnt / node-list-to-array.js
Last active December 13, 2016 16:09
Conversion - NodeList to Array
/**
* This gist is for Javascript beginners.
* @author: Anthony Du Pont <[email protected]>
* @site: https://www.twitter.com/JsGists
*
* Methods like `querySelectorAll()` are handy to select multiple DOM elements at once.
* But these methods return a `NodeList` which is a list of all the matching DOM elements.
* No problem at first glance but when you dig a little bit you'll notice there are some
* issues when you want to manipulate them.
*
@willybahuaud
willybahuaud / default-term.php
Last active October 17, 2022 16:45
Set a default term for custom taxonomy and custom post type
<?php
add_action( 'wp_insert_post', 'willy_set_default_term', 10, 3 );
function willy_set_default_term( $post_id, $post, $update ) {
if ( 'cpt' == $post->post_type ) { // replace `cpt` with your custom post type slug
/**
* Replace `taxo` by the taxonomy slug you want to control/set
* … and replace `default-term` by the default term slug (or name)
* (or you can use a `get_option( 'my-default-term', 'default term' )` option instead, which is much better)
*/
if ( empty( wp_get_post_terms( $post_id, 'taxo' ) ) ) {
@ayamflow
ayamflow / gist:b602ab436ac9f05660d9c15190f4fd7b
Created May 9, 2016 19:10
Safari border-radius + overflow: hidden + CSS transform fix
// Add on element with overflow
-webkit-mask-image: -webkit-radial-gradient(white, black);
@wpscholar
wpscholar / array-insert-after.php
Created November 7, 2015 13:04
Insert a value or key/value pair after a specific key in an array. If key doesn't exist, value is appended to the end of the array.
<?php
/**
* Insert a value or key/value pair after a specific key in an array. If key doesn't exist, value is appended
* to the end of the array.
*
* @param array $array
* @param string $key
* @param array $new
*
@johnbillion
johnbillion / wp_mail.md
Last active July 7, 2025 13:21
WordPress Emails

WordPress Emails

This document lists all the situations where WordPress sends an email, along with how to filter or disable each email.

This documentation has moved here: https://github.com/johnbillion/wp_mail

@paulirish
paulirish / what-forces-layout.md
Last active August 28, 2025 15:03
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
/*!
* The MIT License (MIT)
*
* Copyright (c) 2016 by Blake Bowen (http://codepen.io/osublake/pen/OyPGEo)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@jacobwise
jacobwise / Re-Position-Yoast-SEO-plugin-metabox
Last active June 5, 2018 16:39
Re-position Yoast SEO plugin to high priority. Just change high to low to put it at the bottom.
/**
*
* Filter Yoast SEO Metabox Priority
* @author Jacob Wise
* @link http://swellfire.com/code/filter-yoast-seo-metabox-priority
*
*/
add_filter( 'wpseo_metabox_prio', 'jw_filter_yoast_seo_metabox' );
function jw_filter_yoast_seo_metabox() {
return 'high';
@eikes
eikes / jquery.uncheckable_radio.js
Created March 11, 2014 11:42
jQuery plugin to allow unchecking radio buttons
(function ($) {
$.fn.uncheckableRadio = function () {
return this.each(function () {
var radio = this,
label = $('label[for="' + radio.id + '"]');
if (label.length === 0) {
label = $(radio).closest("label");
}
var label_radio = label.add(radio);
label_radio.mousedown(function () {