Skip to content

Instantly share code, notes, and snippets.

View markhowellsmead's full-sized avatar

Mark Howells-Mead markhowellsmead

View GitHub Profile
@markhowellsmead
markhowellsmead / vh.css
Last active April 9, 2021 11:31
Dynamically observe browser height (accounts for changes in e.g. iOS Safari on scroll)
:root {
--vh: 1vh;
}
.c-browserheight {
min-height: calc(100 * var(--vh));
}
@markhowellsmead
markhowellsmead / exif-gist.php
Created February 10, 2021 09:40 — forked from black-forever/exif-gist.php
EXIF 01 - Get EXIF-Information from wp_get_attachment_image_attributes
<?php
/**
* *****************************************************************************
* GIST - EXIF 01 - Get EXIF-Information from wp_get_attachment_image_attributes
* *****************************************************************************
*/
if ( is_attachment() ) {
$imgmeta = wp_get_attachment_metadata( $id );
@markhowellsmead
markhowellsmead / full-codes.js
Created January 16, 2021 15:51 — forked from phpbits/full-codes.js
Extend core Gutenberg blocks with custom attributes and settings. View full tutorials here : https://jeffreycarandang.com/extending-gutenberg-core-blocks-with-custom-attributes-and-controls/
/**
* External Dependencies
*/
import classnames from 'classnames';
/**
* WordPress Dependencies
*/
const { __ } = wp.i18n;
const { addFilter } = wp.hooks;
@markhowellsmead
markhowellsmead / CustomizerPolylang.php
Last active December 14, 2020 16:26
This add-in gives you full Polylang support in WordPress customizer. By full support I mean that you customize each language site differently. Original from https://github.com/soderlind/customizer-polylang
<?php
/**
* This add-in gives you full Polylang support in WordPress customizer. By full support I mean that you customize each language site differently.
* Minor adaptation from https://github.com/soderlind/customizer-polylang to fit into the Hello Roots logic.
*/
namespace SayHello\Theme\Plugin;
class CustomizerPolylang
@markhowellsmead
markhowellsmead / Gutenberg.php
Created May 19, 2020 10:51
Add post type and slug to Gutenberg editor wrapper
<?php
/**
* Extend the Gutenberg Package with the following function
*/
add_filter('admin_body_class', [$this, 'extendAdminBodyClass']);
<!-- wp:group {"align":"full"} --><div class="wp-block-group alignfull"><div class="wp-block-group__inner-container"><!-- wp:columns --><div class="wp-block-columns"><!-- wp:column --><div class="wp-block-column"><!-- wp:heading {"level":4} --><h4>Menu 1</h4><!-- /wp:heading --><!-- wp:list {"className":"is-style-none"} --><ul class="is-style-none"><li><a href="#">Entry 1</a></li><li><a href="#">Entry 2</a></li><li><a href="#">Entry 3</a></li><li><a href="#">Entry 4</a></li></ul><!-- /wp:list --></div><!-- /wp:column --><!-- wp:column --><div class="wp-block-column"><!-- wp:heading {"level":4} --><h4>Menu 2</h4><!-- /wp:heading --><!-- wp:list {"className":"is-style-none"} --><ul class="is-style-none"><li><a href="#">Entry 1</a></li><li><a href="#">Entry 2</a></li><li><a href="#">Entry 3</a></li><li><a href="#">Entry 4</a></li></ul><!-- /wp:list --></div><!-- /wp:column --><!-- wp:column --><div class="wp-block-column"><!-- wp:heading {"level":4} --><h4>Menu 3</h4><!-- /wp:heading --><!-- wp:list {"className"
@markhowellsmead
markhowellsmead / _group.scss
Created April 15, 2020 17:22
Gutenberg: Group: custom styling
.wp-block-group {
margin-top: 0;
margin-bottom: 0;
&.is-style-padding {
.wp-block-group__inner-container {
padding-top: var(--unit);
padding-bottom: var(--unit);
}
@markhowellsmead
markhowellsmead / Plugin.php
Created April 14, 2020 15:14
Gutenberg: enqueue block editor assets (FROM PLUGIN)
<?php
add_action('enqueue_block_editor_assets', [$this, 'enqueueBlockAssets']);
public function enqueueBlockAssets()
{
$dirpath = plugin_dir_path(shp_myplugin_get_instance()->file);
@markhowellsmead
markhowellsmead / heavy.php
Created February 11, 2020 15:07
Heavy and slow WordPress meta query
<?php
public function onlyFutureEntries($query)
{
if (!is_admin() && isset($query->query['post_type']) && $query->query['post_type'] === 'sht_event') {
$query->set('orderby', 'meta_value');
$query->set('order', 'ASC');
$query->set('meta_key', 'start_date');
$meta_query = (array) $query->get('meta_query');
@markhowellsmead
markhowellsmead / aspect_ratio.php
Created November 29, 2019 12:10
Get WordPress post thumbnail image 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 {