Skip to content

Instantly share code, notes, and snippets.

@justintadlock
justintadlock / plugin.php
Last active March 21, 2024 03:38
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 March 4, 2024 22:35
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
Created December 5, 2023 01:33
Add CSP to WordPress, including nonces for inline scripts
<?php
/**
* Plugin Name: Content Security Policy
* Version: 1.0.0
* Description: Adds a Content-Security-Policy header to all non-admin requests.
* 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'
@awps
awps / get_page_by_title_wp_query.php
Created June 25, 2023 23:39
Alternative to the deprecated `get_page_by_title`, using WP_Query
<?php
function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) {
$query = new WP_Query(
array(
'post_type' => $post_type,
'title' => $page_title,
'post_status' => 'all',
'posts_per_page' => 1,
'no_found_rows' => true,
'ignore_sticky_posts' => true,
@lennardv2
lennardv2 / archivedl.php
Created June 1, 2023 13:39 — forked from divinity76/archivedl.php
Fork of archivedl.php to make it work with php8.2
#!/usr/bin/php
<?php
declare(strict_types = 1);
// require_once ('hhb_.inc.php');
hhb_init ();
if ($argc !== 3) {
fprintf ( STDERR, "usage: %s timestamp url\n", $argv [0] );
fprintf ( STDERR, "example: %s 20091012061648 http://www.p4w.se\n", $argv [0] );
die ( 1 );
}
<?php
/**
* Optimize Loading Separate Core Block Assets in Classic Themes Plugin.
*
* @package OptimizeLoadingSeparateCoreBlockAssetsInClassicThemes
* @author Weston Ruter
* @link https://gist.github.com/westonruter/25187db63a7666f08b151ca53497ffb5
* @license GPL-2.0-or-later
* @copyright 2023 Google Inc.
*