Skip to content

Instantly share code, notes, and snippets.

Mark Howells-Mead markhowellsmead

Block or report user

Report or block markhowellsmead

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
markhowellsmead / aspect_ratio.php
Created Nov 29, 2019
Get WordPress post thumbnail image aspect ratio
View aspect_ratio.php
$featured_image_atts = wp_get_attachment_image_src(get_post_thumbnail_id(), 'post_thumbnail');
$aspect_ratio = $featured_image_atts[1]/$featured_image_atts[2];
if ($aspect_ratio < 1) {
$image_size = 'post_thumbnail_tall';
} elseif ($aspect_ratio === 1) {
$image_size = 'post_thumbnail_square';
} else {
markhowellsmead / serverside.php
Created Oct 29, 2019
Hello Roots ServerSideRender: use LazyImage for frontend and static generation in backend
View serverside.php
if (array_key_exists('context', $_GET) && $_GET['context'] === 'edit') {
$featured_image = wp_get_attachment_image(get_post_thumbnail_id($post->ID), $size, false, ['class' => 'b-articles-latest__entryimage']);
if (!empty($featured_image)) {
$featured_image = '<figure class="b-articles-latest__entryfigure">'.$featured_image.'</figure>';
} else {
$featured_image = sht_theme()->Package->Lazysizes->getLazyImage(get_post_thumbnail_id($post->ID), $size, 'b-articles-latest__entryfigure', 'b-articles-latest__entryimage');
markhowellsmead / getTemplatePart.php
Last active Oct 24, 2019
Alternative to WordPress' get_template_part function , which allows you to pass data to the template part. Requires PHP 7+ because of the coalescing operator. Info at
View getTemplatePart.php
public function getTemplatePart(string $file_path, ...$arguments)
$data = [];
// Array containing possible paths to the template part
$parts = (array) $file_path;
if (is_array($arguments)) {
markhowellsmead / event_query.php
Last active Oct 22, 2019
Complex WordPress meta query by start and end date (custom meta fields)
View event_query.php
* Complex WordPress meta query by start and end date (custom meta fields)
* Intended for use on the `pre_get_posts` hook.
* Caution; this makes the query very slow - several seconds - so should be
* implemented with some form of caching.
* 22.10.2019, based on code from 201 onwards
markhowellsmead / add-wordpress-settings-page.php
Created Oct 3, 2019 — forked from DavidWells/add-wordpress-settings-page.php
WordPress :: Add Settings Page with All Fields
View add-wordpress-settings-page.php
Plugin Name: Homepage Settings for BigBang
Plugin URI:
Description: Adds additional functionality to the big bang theme.
Author: David Wells
Author URI:
// Specify Hooks/Filters
markhowellsmead / date_comparison.php
Last active Sep 25, 2019
Convert one or two dates (date from and date to) into a sensible, legible date string
View date_comparison.php
* Convert one or two dates (date from and date to) into a sensible, legible date string
* @param array $dates Array containing 'date_from' and (optionally) 'date_to'
* @return string Human-readable date text
public function courseEntryDate(array $dates)
$dates['date_from'] = $dates['day'];
$dates['date_to'] = $dates['day_to'];
markhowellsmead / gulpfile.babel.js
Created Sep 16, 2019
Gulp set for JavaScript only in a plugin
View gulpfile.babel.js
import gulp from 'gulp';
import livereload from 'gulp-livereload';
const config = {
name: 'Say Hello - Plugin X',
key: 'shp_plugin_x',
distDir: './dist/',
gulpDir: './gulp/',
assetsBuild: './source/',
errorLog: function(error) {
markhowellsmead / Vendor_ImageSelector.jsx
Created Aug 26, 2019
Media selector for Say Hello components
View Vendor_ImageSelector.jsx
* Media selector for Say Hello components
* 26.8.2019
* Usage: <ImageSelector
allowed_types={['image/jpg', 'image/jpeg', 'image/png']}
markhowellsmead / block.jsx
Created Aug 22, 2019
Gutenberg: Starter Block Code
View block.jsx
const { RichText } = wp.blockEditor;
const { _x } = wp.i18n;
wp.blocks.registerBlockType('sht/starter-block', {
title: _x('Starter Block', 'Block title', 'sha'),
icon: 'heading',
category: 'sht/theme',
attributes: {
title: {
type: 'string',
markhowellsmead / block.jsx
Last active Oct 2, 2019
Gutenberg: MediaUpload Component (add to InspectorControls)
View block.jsx
const {MediaUpload, MediaUploadCheck} = wp.blockEditor;
onSelect={clienticon => {
getLazySrcs(, 'smallsquare').then(clienticon => this.props.setAttributes({clienticon}));
allowedTypes={['image/jpg', 'image/jpeg', 'image/png']}
You can’t perform that action at this time.