Skip to content

Instantly share code, notes, and snippets.

View markhowellsmead's full-sized avatar

Mark Howells-Mead markhowellsmead

View GitHub Profile
@markhowellsmead
markhowellsmead / download_jimdo_images.js
Last active January 30, 2025 13:14
Download full-size images from a Jimdo page containing galleries
/**
* Run this in the browser's developer console.
* Provided with no guarantees! Worked perfectly when published.
*
* mark-at-sayhello.ch / 30.1.2025
*/
(()=> {
let galleryCounters = {}; // Stores counters for each gallery legend
@markhowellsmead
markhowellsmead / block-bindings.php
Created November 14, 2024 11:40
Example usage of block bindings
<?php
register_block_bindings_source('my-custom-prefix/current-year', [
'label' => __('Current year', 'my-custom-prefix'),
'get_value_callback' => 'my_custom_prefix_current_year',
]);
function my_custom_prefix_current_year()
{
@markhowellsmead
markhowellsmead / Block.php
Created June 5, 2024 13:11
Add a do_action using the render_block filter
<?php
namespace PT\MustUse\Blocks\CoreEmbed;
class Block
{
public function run()
{
add_filter('render_block_core/embed', [$this, 'render'], 10, 2);
}
@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'
@markhowellsmead
markhowellsmead / index.js
Last active March 9, 2023 15:12
First example of GitHub Copilot. Gets posts from the WordPress REST API and appends them to the postContainer.
// get the current site's REST API base url
const restApiBaseUrl = wpApiSettings.root;
// get the element with the class name '.posts-container' from the document
const postsContainer = document.querySelector('.posts-container');
// use restApiBaseUrl to get all of the posts from the rest api in a recursive async function. wrap the function in an IIFE.
// append the posts to the posts container as objects. add a class name to each element using the classNameBase 'shp-my-posts' and the post id.
(async function getPosts() {
// stop processing if there is no posts container
@markhowellsmead
markhowellsmead / updatelive.sh
Created April 21, 2022 12:35
Bash script with coloured messaged
#!/bin/bash
function cecho(){
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"
NC="\033[0m" # No Color
printf "${!1}\n${2} ${NC}"
}
@markhowellsmead
markhowellsmead / PostFeaturedImage.php
Created March 11, 2022 17:29
WordPress Gutenberg: add preset size selector to core Post Featured Image block
<?php
namespace SayHello\Theme\Block;
use WP_Block;
/**
* Core Post Featured Image block
* From plugin
*
@markhowellsmead
markhowellsmead / PostMoreSameCategory.php
Last active March 9, 2022 09:42
Gutenberg: server side render with editable title
<?php
namespace SayHello\Theme\Block;
use WP_Term;
/**
* More posts from same category as current post
*
* @author Say Hello GmbH <[email protected]>
@markhowellsmead
markhowellsmead / extend_admin_search.php
Created March 3, 2022 17:49
Extend WordPress admin media search to include custom meta fields
<?php
add_action( 'pre_get_posts', 'extend_admin_search' );
function extend_admin_search( $query ) {
$post_type = 'post';
$custom_fields = array("source",);
if( ! is_admin() )
return;
if ( $query->query['post_type'] != $post_type )
return;
@markhowellsmead
markhowellsmead / block.php
Created February 25, 2022 14:18
Use alignment in server-side rendered blocks for WordPress Gutenberg
<?php
register_block_type('shb/demo', [
'attributes' => [
'align' => [
'type' => 'string',
'enum' => ['wide', 'full'],
]
],