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 / remove-slider-revolution-metabox.php
Last active January 15, 2024 16:02
WordPress: Remove Slider Revolution metabox from certain post types
<?php
/**
* Remove Slider Revolution metabox from certain post types.
* This includes removing it from the top of ACF field groups.
*/
add_action('do_meta_boxes', function (): void {
if (!is_admin()) {
return;
}
@joshuafredrickson
joshuafredrickson / csp-mu-plugin.php
Last active April 30, 2025 23:34
Add CSP to WordPress, including nonces for inline scripts
<?php
/**
* Plugin Name: Content Security Policy
* Version: 1.0.1
* Description: Adds a Content-Security-Policy header to all non-admin requests.
* Requires PHP: 8.1
* Requires at least: 5.7.0
* License: GNU General Public License v2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Original Inspiration: https://gist.github.com/westonruter/c8b49406391a8d86a5864fb41a523ae9
@joshuafredrickson
joshuafredrickson / filters.php
Last active May 5, 2024 08:24
Preload font files found in Roots Sage 10 (bud.js) manifest.json
<?php
use Illuminate\Support\Str;
/**
* Add `rel="preload"` to font files found in the manifest
*/
add_filter('wp_head', function (): void {
echo collect(
json_decode(asset('manifest.json')->contents())
@joshuafredrickson
joshuafredrickson / remove-exif.php
Created September 7, 2023 16:23
WordPress MU Plugin: Strip EXIF data from images
<?php
/**
* Remove EXIF data from .jpg when uploaded.
*/
use Imagick;
/**
* Strip EXIF using Imagick, fallback to gd
@joshuafredrickson
joshuafredrickson / app.js
Created May 16, 2023 14:05
Dynamically loading Alpine components on page load.
import domReady from '@roots/sage/client/dom-ready';
/**
* Alpine components
*/
import Alpine from 'alpinejs';
import * as components from './components/index.js';
/**
@joshuafredrickson
joshuafredrickson / rest-api-seo.php
Created December 13, 2022 20:05
The SEO Framework REST API endpoints for WordPress
<?php
/**
* REST API
* The SEO Framework
*
* @package scout_rest_theme
*
* List of title methods
* @link https://github.com/sybrew/the-seo-framework/issues/202#issuecomment-412781194
*
@joshuafredrickson
joshuafredrickson / bud.config.js
Created March 5, 2022 18:38
Bud: Create additional entrypoint for conditional enqueuing
module.exports = async (app) => {
app
/**
* Application entrypoints
*
* Paths are relative to your resources directory
*/
.entry({
app: {
import: ['@scripts/app', '@styles/app'],
@joshuafredrickson
joshuafredrickson / block-editor-cleanup.php
Last active April 19, 2022 13:47
Block Editor Cleanup for WordPress 5.9 and Classic Editor (mu-plugin)
<?php
/**
* Plugin Name: Block Editor Cleanup
* Plugin URI: https://github.com/WordPress/gutenberg/issues/38299#issuecomment-1025520487
* Version: 1.0.1
* Description: Remove WP 5.9 default block editor styles when using Classic Editor
* Author: joshuafredrickson
* Author URI: https://joshuafredrickson.com
* License: GNU General Public License v2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
@joshuafredrickson
joshuafredrickson / ViewComposer.php
Last active February 3, 2022 17:59
Megamenu in Blade using Alpine JS
<?php
namespace App\View\Composers;
use Roots\Acorn\View\Composer;
use Log1x\Navi\Facades\Navi;
use function App\get_parent;
use function acf_get_attachment;
class NavHeader extends Composer
@joshuafredrickson
joshuafredrickson / wp-cli-install.sh
Created January 31, 2022 22:13
Install wp-cli on shared hosting
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
mkdir ~/bin
mv wp-cli.phar ~/bin/wp