Skip to content

Instantly share code, notes, and snippets.

View joshuafredrickson's full-sized avatar
🍊
Orange pineapple

Joshua Fredrickson joshuafredrickson

🍊
Orange pineapple
View GitHub Profile
@joshuafredrickson
joshuafredrickson / gutenberg.php
Last active October 9, 2020 20:58
WordPress Block Editor: Define a block template that includes a reusable block
<?php
/**
* Define a block template for a post type that includes a reusable block.
* Find the reusable block ID at /wp-admin/edit.php?post_type=wp_block
*
* @return void
*/
add_action('init', function () {
$post_type_object = get_post_type_object('page'); // Set the post type
query NODE_LIST_QUERY($first: Int!, $after: String) {
posts(first: $first, after: $after, where: { parent: null }) {
nodes {
acfFeaturedImage {
fieldGroupName
scoutFeaturedImageOverride {
id
sourceUrl
}
scoutFeaturedImageShow
@joshuafredrickson
joshuafredrickson / wp-cli-install.sh
Created April 6, 2020 21:13
Install latest wp-cli
mkdir $HOME/bin; wget -O $HOME/bin/wp https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && chmod +x $HOME/bin/wp && echo "export PATH=$HOME/bin:$PATH" | tee -a $HOME/.bashrc && source $HOME/.bashrc; wp --info
@joshuafredrickson
joshuafredrickson / acf-image.blade.php
Created January 20, 2020 17:56
Quick and dirty responsive <picture> component for ACF images
{{--
$image: ACF image field
$images: \App\get_image_sizes($image_id)
$class
$alt
$width: Optionally define how wide this image should be at different breakpoints
--}}
<picture class="acf-image {{ $class ?? '' }}">
<source srcset="
@joshuafredrickson
joshuafredrickson / gutes.html
Last active April 30, 2019 13:46
native-gutenberg notes
<!-- wp:paragraph -->
<p>Donec id elit non mi porta gravida at eget metus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec ullamcorper nulla non metus auctor fringilla.</p>
<!-- /wp:paragraph -->
<!-- wp:more -->
<!--more-->
<!-- /wp:more -->
<!-- wp:heading {"level":1} -->
<h1>Heading One</h1>
@joshuafredrickson
joshuafredrickson / blocks.php
Created April 29, 2019 17:28
Updated config/blocks.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Register theme color palette
|--------------------------------------------------------------------------
|
| Colors defined in this array will be registered with the
@joshuafredrickson
joshuafredrickson / remove-exif.php
Last active December 21, 2023 10:10
WordPress Plugin: Automatically remove EXIF data from .jpgs when uploaded
<?php
/**
* Plugin Name: Remove EXIF data
* Plugin URI: https://gist.github.com/joshuafredrickson/cd5ab346992f533ecbe976d365fa36dd
* Version: 1.0.0
* Description: Remove EXIF data from .jpg when uploaded.
* Author: Joshua Fredrickson
* Author URI: https://joshuafredrickson.com
* License: GNU General Public License v2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
@joshuafredrickson
joshuafredrickson / functions.php
Created February 12, 2019 17:13
WordPress: Create column-based add_image_sizes using Laravel collect()
<?php
/**
* Image sizes
* Finds the width for each column size based on a max container width (1600) and column count.
*/
collect([3, 6, 9, 12])->map(function($column) {
return add_image_size($column . '/12', $column / 12 * 1600);
});
@joshuafredrickson
joshuafredrickson / functions.php
Created February 12, 2019 16:05
WordPress: Generate @2x image sizes automatically.
<?php
/**
* @2x image sizes
*/
function make_it_retina($file, $width, $height, $crop = false) {
if ($width || $height) {
$resized_file = wp_get_image_editor($file);
if (!is_wp_error($resized_file)) {
$resized_file->resize($width * 2, $height * 2, $crop);
@joshuafredrickson
joshuafredrickson / no-nags.php
Created January 29, 2019 14:46
WordPress: Move all admin notices and plugin nags to console
add_action('plugins_loaded', function() {
$action = is_user_admin() ? 'user_admin_notices' : 'admin_notices';
add_action($action, function () {
ob_start();
});
add_action('all_admin_notices', function () {
$log = strip_tags(trim(ob_get_clean()));