Skip to content

Instantly share code, notes, and snippets.

View jdevalk's full-sized avatar

Joost de Valk jdevalk

View GitHub Profile

Playground Comment Worker

This simple playground.yml creates a comment that opens a WordPress Playground and installs the plugin from the current repository. The current iteration only works with plugins that do not require a build step.

Playground test comment in action

CORS issues

Because GitHub doesn't send the right CORS headers for zip files to be able to install them in a Playground, you need a reverse proxy to bypass the CORS restrictions. The Worker below in worker.js can be used as a Cloudflare worker that

Scripts for getting the number of tags and posts on a site

If a WordPress site doesn't have XML sitemaps, or you can't find them, there are a number of ways to figure out how many tags and posts that site has. The easiest way is by using the REST API to get the number. Note both scripts below are fairly similar and could probably be simplified. Also: please don't run this on sites too aggressively. Not all sites handle getting 100 posts from their REST API endpoints very well.

jdevalk /
Last active January 26, 2024 07:20

EDD Multi-currency currency by country switcher

The worker.js Cloudflare worker below determines the currency and sets a cookie. The PHP code reads the cookie and sets the session currency in EDD.

jdevalk / gist:5623050
Created May 21, 2013 20:39
Redirect script sample NGINX code. Make sure this location line sits above the "location /" code in your NGINX config.
location /redirect/ {
rewrite ^/redirect/(.*)$ /redirect/index.php?id=$1 last;
jdevalk / .htaccess
Last active November 28, 2023 20:28
These three files together form an affiliate link redirect script.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule (.*) ./index.php?id=$1 [L]
jdevalk / xmlrpc.php
Created June 12, 2023 11:14
If you're not using XMLRPC, this will save tons of uncached requests to your site, assuming your homepage is cached properly.
$protocol = 'https';
if ( ! isset( $_SERVER['HTTPS'] ) || $_SERVER['HTTPS'] === 'off' ) {
$protocol = 'http';
$url = $protocol . "://" . $_SERVER['HTTP_HOST'];
header( 'Location: ' . $url, true, 301 );
jdevalk / author-itemprop.php
Last active January 17, 2023 09:58
Bits of schema that require non-schema filters right now, for which I've written these functions
// For pages where you'd rather not have 20 rel=authors and in fact *do* need itemprop=author
// For instance on
function yoast_author_schema( $output ) {
return str_replace( 'rel="author"', 'itemprop="author"', $output );
add_filter( 'genesis_post_author_posts_link_shortcode', 'yoast_author_schema', 20 );
jdevalk / copyrightholder.php
Last active January 6, 2022 04:00
This is how to add the copyrightHolder schema to the Website Schema piece Yoast SEO outputs.
add_filter( 'wpseo_schema_website', 'example_change_website_schema', 10, 2 );
* Changes the Yoast SEO Website schema.
* @param array $data The Schema Website data.
* @param Meta_Tags_Context $context Context value object.
jdevalk / archive-speaking_event.php
Last active December 12, 2021 20:13
Genesis helper code for schema
add_filter( 'genesis_attr_content', 'yoast_schema_empty', 20 );
add_filter( 'genesis_attr_entry', 'yoast_schema_event', 20 );
add_filter( 'genesis_attr_entry-title', 'yoast_itemprop_name', 20 );
add_filter( 'genesis_attr_entry-content', 'yoast_itemprop_description', 20 );
add_filter( 'genesis_post_title_output', 'yoast_title_link_schema', 20 );
* We'll use the post info output to add more meta data about the event.
jdevalk / logging-helper.php
Last active December 9, 2021 16:25
This little hack enables fatal error logging for your site, without creating an error log that is insanely big.
* This changes logging to only log fatal errors. This file should go in your mu-plugins directory.
// Set the error logging to only log fatal errors
error_reporting( E_ERROR );
// Optional: change the location of your error log, it might be wise to put it outside your WP content dir.
// If you don't change it, the default place for this log is debug.log in your WP_CONTENT_DIR.