Skip to content

Instantly share code, notes, and snippets.

@fabiankaegy
fabiankaegy / default-rendering-mode.js
Created December 5, 2024 16:43
Set default rendering mode in WordPress 6.6+
import { registerPlugin } from '@wordpress/plugins';
import { useDispatch, useSelect } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
import { store as editorStore } from '@wordpress/editor';
// Define post types that show the full template locked site editor by default.
const TEMPLATE_LOCKED_POST_TYPES = ['page', 'post'];
registerPlugin('namespace-set-default-template-rendering-mode', {
render: function Edit() {
@adrienne
adrienne / mullenweg-wpe.md
Last active May 12, 2025 16:34
The Mullenweg/WPE Thing
@justintadlock
justintadlock / plugin.php
Last active January 10, 2025 03:58
Virtual page templates with block support
<?php
// This filter specifically checks whether a theme has a `changelog` template.
// If not, it looks for a fallback template in the plugin.
add_filter( 'template_include', function( $template ) {
// I'm just testing a query string here for demonstration/testing
// purposes, but you'll want to add a check for your registered query
// var with WordPress. For now, you can test with `?changelog=anything`.
if ( ! isset( $_GET['changelog'] ) ) {
@dkjensen
dkjensen / README.md
Last active November 17, 2024 16:25
WordPress Query Block as Splide Carousel

Instructions

  1. Add your query block, and give it a class of is-style-carousel.
  2. Add the code from block-editor.php somewhere such as your child theme functions.php file.
  3. Configure Splide options in the query_carousel_block_init() function.
@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
@joemcgill
joemcgill / README.md
Last active April 15, 2024 08:35
WPP Better Image Sizes is a proof of concept WordPress plugin that provides a better calculation for the default sizes attribute for images.

WPP Better Image Sizes

This is a WordPress Plugin that improves the default sizes attribute calculation for images.

Description

WPP Better Image Sizes is a WordPress plugin that provides a better calculation for the default sizes attribute for images. This plugin is designed to enhance the performance and responsiveness of your WordPress site.

Installation

@ryanwelcher
ryanwelcher / edit.js
Created October 12, 2023 18:24
Using the useBlockEditingMode hook
/**
* WordPress Dependencies
*/
import {
useBlockProps,
useBlockEditingMode,
RichText,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
@pbearne
pbearne / performance-conditional-options.php
Last active December 1, 2023 19:21
experimentally caching of the needed options per page
<?php
class CacheOptionPerPage {
private static $conditional_options_context;
private static $alloptions_names = array();
private static $alloptions_used = array();
private static $current_context;
@markhowellsmead
markhowellsmead / update-post-template.php
Last active August 9, 2023 19:20
Update post template for posts matching a certain criteria
<?php
$args = [
'post_type' => 'post',
'posts_per_page' => -1,
'post_status' => 'any',
'meta_query' => [
[
'key' => 'hide_thumbnail',
'compare' => 'EXISTS'
@herbie4
herbie4 / hhdev-wp-redir-all-emails-on-staging.php
Created June 29, 2023 12:23
Bedrock mu-plugin: redirect all emails to specified email when on staging environment. Change the email as needed!
<?php
// Bedrock mu-plugin: redirect all emails to developer email on staging site
// Don't forget to set your email address!
add_filter( 'wp_mail', 'hhdev_staging_email_filter', 10, 1 );
function hhdev_staging_email_filter( $args ) {
if (getenv('WP_ENV') == 'staging') {