Skip to content

Instantly share code, notes, and snippets.

View dotherightthing's full-sized avatar

Dan Smith dotherightthing

  • Do The Right Thing
  • Wellington, New Zealand
View GitHub Profile
@dotherightthing
dotherightthing / changelog.sh
Last active May 17, 2020 01:24
Generate Git changelog #github #releases
git log --pretty="* [%h] %s (%ar)" --no-merges $(git describe --tags --abbrev=0 @^)..@ > changelog.txt
@dotherightthing
dotherightthing / breakpoints.scss
Last active July 27, 2020 21:31
Responsive breakpoints for media queries #scss #include-media #layout
// Breakpoints for include-media
// Usage: @include media(">phone", "<=tablet") { ... }
// Usage: @include media("<=1150px") { ... }
//
// See: https://include-media.com/
// See: https://gs.statcounter.com/screen-resolution-stats
// See: https://gist.github.com/dotherightthing/06f33bf784279aa24072e0b6873c968c
// See: https://elementqueries.com/ (future technology)
//
// Phones:
@dotherightthing
dotherightthing / js-head.php
Last active July 27, 2020 21:31
Google Tag Manager snippet #wordpress #templates #library #seo
/**
* Add Google Tag Manager
*
* @see http://kb.dotherightthing.dan/seo/google-tag-manager-gtm/
* @example
* add_action( 'wp_enqueue_scripts', 'wpdtrt_dbth_js_link_gtm' )
*/
function wpdtrt_dbth_js_link_gtm() {
/**
* Link assets to theme version to ensure user gets the latest version
@dotherightthing
dotherightthing / navigation-footer.php
Last active May 3, 2020 01:03
Register menus #wordpress #library
@dotherightthing
dotherightthing / featured-image-shortcode.php
Created May 2, 2020 23:30
Featured image shortcode #wordpress #library
@dotherightthing
dotherightthing / archive-remove-category-tag-author.php
Created May 2, 2020 22:33
Remove “Category:”, “Tag:”, “Author:” from the_archive_title #wordpress #library
/**
* Remove “Category:”, “Tag:”, “Author:” from the_archive_title
*
* @param string $title Title.
* @return string $title
* @see http://wordpress.stackexchange.com/questions/179585/remove-category-tag-author-from-the-archive-title
* @example
* add_filter( 'get_the_archive_title', 'wpdtrt_remove_archive_from_archive_title' );
*/
function wpdtrt_remove_archive_from_archive_title( $title ) {
@dotherightthing
dotherightthing / remove-blocking-js.php
Created May 2, 2020 14:10
Remove blocking JS #wordpress #cheatsheet
/**
* Deregister only those scripts which are incorrectly output into the head.
* Then reregister these to load into the footer.
* This leaves wp_head load actions intact for scripts that we deem worthy (such as GTM).
*
* @see http://justintadlock.com/archives/2009/08/06/how-to-disable-scripts-and-styles
* @example add_action( 'wp_print_scripts', 'wpdtrt_deregister_head_js', 100 );
*/
function wpdtrt_deregister_head_js() {
@dotherightthing
dotherightthing / add-taxonomy-terms.php
Created May 2, 2020 14:09
Add terms to a custom taxonomy #wordpress #cheatsheet
/**
* This cannot use PHP variables without violating theme-check (i18n),
* but a static generator such as Mustache.php could be an option.
*/
/**
* Seed a custom taxonomy with terms
* Note: Save Permalinks after changing this.
* save_post is run on save, publish, update and bulk/quick edit
*
@dotherightthing
dotherightthing / register-taxonomy.php
Created May 2, 2020 14:07
Register a taxonomy #wordpress #cheatsheet
/**
* This cannot use PHP variables without violating theme-check (i18n),
* but a static generator such as Mustache.php could be an option.
*/
/**
* Register taxonomy
*
* @uses ../../../../wp-includes/taxonomy.php
* @see https://codex.wordpress.org/Function_Reference/register_taxonomy
@dotherightthing
dotherightthing / register-and-get-sidebar.md
Last active January 21, 2021 22:04
Register a widget-ready sidebar #wordpress #cheatsheet