Skip to content

Instantly share code, notes, and snippets.

View dmje's full-sized avatar

Mike Ellis dmje

View GitHub Profile
@dmje
dmje / Add taxonomy and populate with initial values.php
Created November 20, 2025 10:20
Was using on WPClientPro but no longer
<?php
// Add taxonomy to the Space Content CPT and populate with initial values
if ( ! taxonomy_exists( 'space-content-type' ) ) {
// Define your taxonomy labels
$labels = array(
'name' => _x( 'Content Types', 'taxonomy general name', 'textdomain' ),
'singular_name' => _x( 'Content Type', 'taxonomy singular name', 'textdomain' ),
'search_items' => __( 'Search Content Types', 'textdomain' ),
@dmje
dmje / Open Graph with Yoast - amend
Created November 20, 2025 10:04
This one seems to work. Example deployed to MoDA on 24/09/20. See link to Gist below for other examples.
<?php
// Change OG image for single objects
// Based on snippet here https://gist.github.com/amboutwe/811e92b11e5277977047d44ea81ee9d4
add_filter( 'wpseo_opengraph_image', 'change_opengraph_image_url' );
function change_opengraph_image_url( $url )
{
@dmje
dmje / WordPress ALT tags.php
Created August 14, 2025 09:14
The problem: if you add ALT tags after adding images to a page, WordPress doesn't by default use these (WTF!) - add this to functions to sort...
<?php
// Sorting out image ALTs
// from https://www.billerickson.net/code/wordpress-image-automatic-alt-text/
add_filter('render_block',
function ($content, $block) {
if ('core/image' !== $block['blockName']) {
return $content;
@dmje
dmje / single-object.php
Created April 8, 2025 14:57
MDS - Culture Object Spectrum display
<?php
function unserialize_meta_data($data) {
if (is_array($data)) {
foreach ($data as $key => &$item) {
if (is_array($item) && isset($item[0]) && is_serialized($item[0])) {
$item = maybe_unserialize($item[0]);
}
}
}
<!--put this in a code block at top of mailing-->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto+Slab:[email protected]&family=Source+Serif+4:ital,opsz,wght@0,8..60,200..900;1,8..60,200..900&display=swap" rel="stylesheet">
<style>
p {
font-family: "Roboto Slab", serif !important;
{
"name": "Poopers",
"description": "My first widget.json.",
"data": {
"content_url": "https://thirty8.co.uk/"
},
"layouts": {
"hello_small": {
"size": "small",
"styles": {
<?php
add_action( 'init', 'create_my_post_types' );
function create_my_post_types() {
register_post_type('exhibition', array(
'labels' => array(
'name' => __( 'Exhibitions' ),
'singular_name' => __( 'Exhibition' ),