Skip to content

Instantly share code, notes, and snippets.

View doubleedesign's full-sized avatar

Leesa Ward doubleedesign

View GitHub Profile
@doubleedesign
doubleedesign / _typescales.scss
Last active January 15, 2018 12:32
Improved SCSS mixin to easily utilise the proportional type settings chosen using type-scale.com. A streamlining of my previous mixins - https://gist.github.com/doubleedesign/45850d90c80deef79880361f984a3136
/*==============================================
TYPE SCALES - inspired by www.type-scale.com
Notes:
- The base font size and line height are set as variables, called in _typography.scss
- H1s are two steps up from H2s to make them stand out more
- Paragraph margins don't change according to type scale used so they are set once in _typography.scss
- The base font size can be changed at different breakpoints and the type will scale accordingly since it's set in ems.
- Breakpoint mixins and/or media queries can be used to change the typescale at different viewports
==============================================*/
@doubleedesign
doubleedesign / woo-custom-image-sizes.php
Created March 4, 2018 04:09
Customise width and height of WooCommerce images since the way it handles images changed in 3.3. More detail on these filters at https://github.com/woocommerce/woocommerce/wiki/Customizing-image-sizes-in-3.3
<?php
// Customise the product image and gallery thumbnail to ensure they match
function doublee_custom_woo_images() {
return array(
'width' => 600,
'height' => 476,
'crop' => 1,
);
}
add_filter( 'woocommerce_get_image_size_gallery_thumbnail', 'doublee_custom_woo_images' );
@doubleedesign
doubleedesign / wrapThis.js
Created March 27, 2018 01:48
Wrap an element in a specified tag with specified classes, using vanilla JavaScript
/**
* Wrap an element
* @param elementToWrap - selector of element to wrap
* @param elementToUse - HTML tag to use for the wrapper
* @param classes - class(es) to add; accepts string or array
* @returns {Node | *}
*/
function wrapThis(elementToWrap, elementToUse, classes) {
var wrapper = document.createElement(elementToUse);
elementToWrap.parentNode.appendChild(wrapper);
@doubleedesign
doubleedesign / multi-column-lists.js
Last active March 27, 2018 02:54
Adds .dual-column class to the specified list element (ul or ol) when they have more than the specified number of list items, using vanilla JavaScript
/**
* Multi-column long lists
* Adds .dual-column class to the specified list element (ul or ol) when they have more than the specified number of list items
* @param selectedList - selector of lists to run the function on. Expects an array (i.e. use querySelectorAll)
* @param lengthToBreakAt - how many list items there should be before adding dual-column class
*/
function multiColumnList(selectedList, lengthToBreakAt) {
var selector = selectedList;
for (var i = 0; i < selector.length; i++) {
var listItems = selector[i].querySelectorAll('li');
@doubleedesign
doubleedesign / setHeightToHighest.js
Created April 24, 2018 02:43
Get the heights of all elements that match the given selector, and set all of them to the height of the highest one
/**
* Get the heights of all elements that match the given selector, and set all of them to the height of the highest one
* Note: According to https://coderwall.com/p/kvzbpa/don-t-use-array-foreach-use-for-instead, a for loop is faster than forEach
* @param selector - the CSS selector to set to the highest
*/
function setHeightToHighest(selector) {
// Get our items - returns a NodeList of elements
var items = document.querySelectorAll(selector);
// Create an array to store the heights
var heights = [];
@doubleedesign
doubleedesign / change-excerpt-explanation.php
Created September 5, 2018 02:37
Change the explanatory text in the WordPress excerpt meta box, according to post type.
/**
* Change the excerpt explanation in the backend
* @param $translated_text
* @param $text
* @param $domain
*
* @return string
*/
function doublee_change_excerpt_explanation( $translated_text, $text, $domain ) {
$post_type = get_post_type();
@doubleedesign
doubleedesign / accessibility-admin-notice.php
Created December 4, 2018 00:48
Add a collapsible admin notice with content accessibility tips to posts and pages
function doublee_accessibility_admin_notice() {
$screen = get_current_screen();
if(in_array($screen->id, array('post', 'page'))) { ?>
<div class="notice notice-warning notice-accessibility">
<div id="accessibility-tips" class="meta-box-sortables">
<div id="accessibility_meta" class="postbox closed">
<button type="button" class="handlediv" aria-expanded="false">
<span class="screen-reader-text">Toggle panel: Accessibility Tips</span>
<span class="toggle-indicator" aria-hidden="true"></span>
</button>
@doubleedesign
doubleedesign / excerpt-metabox-to-top.php
Created December 4, 2018 00:51
Move the WordPress Excerpt metabox to the top of post and page edit screens
/**
* Move the excerpt metabox to the top
* @param $post_type
*/
function doublee_custom_excerpt_metabox( $post_type ) {
if(in_array($post_type, array('post','page'))) {
add_meta_box(
'excerpt_meta', __( 'Excerpt' ), 'post_excerpt_meta_box', $post_type, 'temp', 'high'
);
}
@doubleedesign
doubleedesign / breadcrumbs-list.php
Created December 4, 2018 00:52
Mark up Yoast breadcrumbs as an unordered list
<?php
/**
* Filter the output of Yoast breadcrumbs so each item is an <li> with schema markup
* @param $link_output
* @param $link
*
* @return string
*/
function doublee_filter_yoast_breadcrumb_items( $link_output, $link ) {
@doubleedesign
doubleedesign / javascript-delayed-event.js
Created December 9, 2018 09:16
How to delay a JavaScript event within an event listener
function myDelayedThing() {
var mySelectors = document.querySelectorAll('.something');
// Loop through mySelectors
for(var i = 0; i < menuLinks.length; i++) {
// Add 'open' class on mouseover
menuLinks[i].addEventListener('mouseover', function() {
this.classList.add('open');