Skip to content

Instantly share code, notes, and snippets.

View markhowellsmead's full-sized avatar

Mark Howells-Mead markhowellsmead

View GitHub Profile
@markhowellsmead
markhowellsmead / post_with_tag.js
Created February 25, 2022 09:01
Create a single tag, then create a post linked to that tag. Uses async/await.
const remote_domain = 'DOMAIN', // without trailing slash
application_password = 'APPLICATION PASSWORD',
username = 'USERNAME';
const headers = new Headers({
'Content-Type': 'application/json',
'Authorization': 'Basic ' + btoa(username + ':' + application_password)
});
const makePost = async function() {
@markhowellsmead
markhowellsmead / remote_create_post.js
Last active February 25, 2022 08:24
Creates a post on a remote WordPress site, using the REST API and an application password
const remote_domain = 'https://example.org', // without trailing slash
application_password = 'Application password',
username = 'remote_user_name';
const body = JSON.stringify({
title: 'Post using REST API',
content: 'Post content using REST API',
status: 'publish'
});
@markhowellsmead
markhowellsmead / ThreeColumns.php
Last active February 18, 2022 14:54
Register a block pattern using PHP. Fits into the Theme structure of https://github.com/SayHelloGmbH/hello-roots/
<?php
namespace SayHello\Theme\Pattern;
/**
* Manage single block pattern
*
* @author Say Hello GmbH <[email protected]>
*/
class ThreeColumns
@markhowellsmead
markhowellsmead / GroupWithMediaText.php
Last active February 18, 2022 14:54
Register a block pattern using PHP. Fits into the Theme structure of https://github.com/SayHelloGmbH/hello-roots/
<?php
namespace SayHello\Theme\Pattern;
/**
* Manage single block pattern
*
* @author Say Hello GmbH <[email protected]>
*/
class GroupWithMediaText
@markhowellsmead
markhowellsmead / alignment-options.js
Created February 17, 2022 10:52 — forked from wpmark/alignment-options.js
Add alignment options for WordPress core blocks.
// set alignment options for cover, video, and paragraph blocks.
wp.hooks.addFilter(
'blocks.registerBlockType',
'hd-theme/hd-theme',
function( settings, name ) {
if ( name === 'core/cover' || name === 'core/video' || name === 'core/paragraph' || name === 'core/list' ) {
return lodash.assign( {}, settings, {
supports: lodash.assign( {}, settings.supports, {
// allow support for full and wide alignment.
align: ['full', 'wide'],
@markhowellsmead
markhowellsmead / cards.html
Last active November 11, 2021 15:35
Three-column card layout (raw Gutenberg HTML)
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:image {"id":62096,"sizeSlug":"medium","linkDestination":"none"} -->
<figure class="wp-block-image size-medium"><img src="https://permanenttourist.ch/wp-content/uploads/2021/10/20211024-DSCF1065-768x768.jpg" alt="" class="wp-image-62096"/><figcaption>Image caption</figcaption></figure>
<!-- /wp:image -->
<!-- wp:heading {"level":3} -->
<h3 id="card-title">Card title</h3>
<!-- /wp:heading -->
@markhowellsmead
markhowellsmead / wordpress_css_properties_root.php
Last active November 3, 2021 10:14
Replace the CSS Custom Properties assignment to BODY onto the :root element
<?php
/**
* WordPress Core currently assigns the CSS Custom Properties
* to the HTML body element, so CSS Custom Properties assigned
* to :root cannot access them. This is defined by WP_Theme_JSON::ROOT_BLOCK_SELECTOR
* which (at the date of writing) cannot be hooked or modified
* by external means.
*
* This script replaces the assignment from body {…} to :root {…}
@markhowellsmead
markhowellsmead / iframe.js
Created September 30, 2021 08:13 — forked from wlarch/iframe.js
Overwrite/bypass <iframe></iframe> height limit imposed by Wordpress
/**
* Overwrite/bypass <iframe></iframe> height limit imposed by Wordpress
* Original idea from bypass-iframe-height-limit plugin by Justin Carboneau
* Adapted from original /wp-includes/js/wp-embed.js
*/
(function(window, document) {
'use strict';
var supportedBrowser = false;
@markhowellsmead
markhowellsmead / PostTitle.php
Last active August 12, 2021 14:18
Example of how to customise the output of a core block (since WP 5.8). Planned for integration to a Hello Roots Theme.
<?php
namespace SayHello\Theme\Block;
/**
* Customisation of the Core Post Title block
* Find the original core rendering at e.g. wp-includes/blocks/post-title.php
*
* @author Mark Howells-Mead <[email protected]>
*/
@markhowellsmead
markhowellsmead / IntersectionObserver.js
Created August 10, 2021 08:12
IntersectionObserver example
/**
* Example code for a scrolling IntersectionObserver
* Original by Keith Devon https://highrise.digital/blog/animating-blocks-on-scroll-with-intersection-observer/
*
*/
document.addEventListener('DOMContentLoaded', () => {
// get all the scroll-group elemetns.
const scrollGroups = document.querySelectorAll('[class*="scroll-group"]');