Skip to content

Instantly share code, notes, and snippets.

View jplhomer's full-sized avatar

Josh Larson jplhomer

View GitHub Profile
@jplhomer
jplhomer / disable-comments.sh
Created February 25, 2015 16:38
Disable all comments/pings in WordPress with WP-CLI
$ wp post list --format=ids | xargs wp post update --comment_status=closed
# Output:
# Success: Updated post 2514.
# Success: Updated post 2511.
# Success: Updated post 2504.
# Success: Updated post 2499.
# Success: Updated post 2441.
# etc...
// Directive: x-clipboard
Alpine.directive('clipboard', async (el, { expression }) => {
el.addEventListener('click', async () => {
await navigator.clipboard.writeText(expression);
document.dispatchEvent(
new CustomEvent('banner-message', { detail: { style: 'success', message: 'Copied to clipboard!' } })
);
});
});
@jplhomer
jplhomer / woocommerce-alter-cart-total.php
Last active July 10, 2021 01:53
Programmatically alter the WooCommerce cart discount total (and apply a new discount) before it's calculated through the woocommerce_calculate_totals hook. Add this code to your Wordpress functions.php file.
<?php
/**
* Programmatically alter the WooCommerce cart discount total (and apply a new discount) before it's calculated
* through the woocommerce_calculate_totals hook.
*
* For example, if you want to apply an arbitrary discount after a certain number of products in the cart,
* you can loop through that number and increment it as needed.
*
* In this example, I increment the discount by $8.85 after every 15 products added to the cart.
*
@jplhomer
jplhomer / basic.html
Last active December 20, 2017 18:09
Example of loading fonts with loadCSS
<!-- Our font file is fonts.css -->
<script>
/*!
loadCSS: load a CSS file asynchronously.
[c]2014 @scottjehl, Filament Group, Inc.
Licensed MIT
*/
/* exported loadCSS */
@jplhomer
jplhomer / functions.php
Created March 19, 2017 21:19
Set a custom taxonomy for Taghound Media Tagger
<?php
// Your theme's functions.php file...
function custom_tag_taxonomy( $slug ) {
return 'YOUR_CUSTOM_SLUG';
}
add_filter( 'tmt_tag_taxonomy', 'custom_tag_taxonomy', 10, 1 );
@jplhomer
jplhomer / app.scss
Last active February 13, 2017 17:31
Using Laravel Mix for a standalone project
$favorite-color: green;
$pad: 1em;
#app {
background-color: $favorite-color;
h1 {
font-size: $pad * 5;
}
}
@jplhomer
jplhomer / taghound-frontend.php
Created February 13, 2017 14:31
Show Taghound Tags on the front-end of a WordPress post.
<?php
// single.php or whatever template you'd like
// 1. Get the ID of the current thumbnail for the post
$attachment_id = get_post_thumbnail_id();
// 2. Get the tags associated to the image
$tags = wp_get_post_terms($attachment_id, 'tmt_tag');

Keybase proof

I hereby claim:

  • I am jplhomer on github.
  • I am jplhomer (https://keybase.io/jplhomer) on keybase.
  • I have a public key ASC2sjVUdy9XeT2gcSjdtIkjHwyAYYqKI7YTfCDALshl7Ao

To claim this, I am signing this object:

@jplhomer
jplhomer / page-about.php
Created October 25, 2013 03:46
The template to show our custom timeline using Wordpress and Advanced Custom Fields: http://jplhomer.org/2013/10/building-responsive-timeline-advanced-custom-fields/
<?php if ( $events = get_field( 'events' ) ) :
// Re-order our events just in case
if ( get_field('sort_order') == 'Date Descending') {
usort( $events, 'sort_by_date_descending');
} else {
usort( $events, 'sort_by_date_ascending');
}
// Set a year checker to see if we should print a new year
$year = 0;
@jplhomer
jplhomer / pageslide.min.js
Created September 9, 2013 17:44
A small fork of srobbin's jquery-pageslide (https://github.com/srobbin/jquery-pageslide) to enable the touch event in the main container, enabling the menu to be toggled by an off-menu touch on mobile.
/*
* jQuery pageSlide
* Version 2.0
* EDITED BY @jplhomer to enable the toggling of the menu by touching the main content area.
* http://srobbin.com/jquery-pageslide/
*
* jQuery Javascript plugin which slides a webpage over to reveal an additional interaction pane.
*
* Copyright (c) 2011 Scott Robbin (srobbin.com)
* Dual licensed under the MIT and GPL licenses.