Skip to content

Instantly share code, notes, and snippets.

View spacedmonkey's full-sized avatar
🖐️
Open for work

Jonny Harris spacedmonkey

🖐️
Open for work
View GitHub Profile
add_filter( 'get_image_tag', function( $html, $id, $alt, $title, $align, $size ){
$original_url = $this->get_original_url( $id );
if ( ! $original_url ) {
return $html;
}
list( $img_src, $width, $height ) = image_downsize( $id, $size );
$hwstring = image_hwstring( $width, $height );
$html = '<img src="' . $img_src . '" alt="' . esc_attr( $alt ) . '" ' . $title . $hwstring . 'class="' . $class . '" />';
@spacedmonkey
spacedmonkey / hasVideoGotAudio.js
Created August 15, 2021 21:18
Detect if video has audio, using javascript
function hasAudio(video) {
return (
video.mozHasAudio ||
Boolean(video.webkitAudioDecodedByteCount) ||
Boolean(video.audioTracks?.length)
);
}
function hasVideoGotAudio(src) {
const video = document.createElement('video');
video.muted = true;
$post_type_taxonomies = array();
$term_ids = array();
$prime_post_terms = array();
foreach ( $posts as $post ) {
if ( ! ( $post instanceof WP_Post ) ) {
continue;
}
if ( ! isset( $post_type_taxonomies[ $post->post_type ] ) ) {
$post_type_taxonomies[ $post->post_type ] = get_object_taxonomies( $post->post_type );
@spacedmonkey
spacedmonkey / block-style-splitter.php
Created June 19, 2023 14:38
WordPress: Split block styles into maybe enqueues for classic themes.
<?php
/**
*
* @link https://www.spacedmonkey.co.uk
* @since 1.0.0
* @package Style_Splitter
*
* @wordpress-plugin
* Plugin Name: Block style splitter
#!/bin/bash
for branch in trunk 6.2 6.1 6.0 5.9
do
for theme in twentytwentytwo
do
for url in http://localhost:8889/
do
cd wordpress-develop > /dev/null 2>&1;
npm run env:start > /dev/null 2>&1;