Skip to content

Instantly share code, notes, and snippets.

@jnicol
jnicol / functions.php
Created August 22, 2023 22:31
Display advanced custom fields values in WordPress admin columns
View functions.php
/*
* Add columns to exhibition post list
*/
function add_acf_columns ( $columns ) {
return array_merge ( $columns, array (
'start_date' => __ ( 'Starts' ),
'years' => __ ( 'Years' )
) );
}
add_filter ( 'manage_exhibition_posts_columns', 'add_acf_columns' );
@jnicol
jnicol / fix-mail-return-path.php
Created May 5, 2023 23:00
Fix WordPress wp_mail Return Path header, which is used for SPF checks, so that it matches From domain.
View fix-mail-return-path.php
<?php
/*
Plugin Name: Email Return Path Fix
Author: Abdussamad Abdurrazzaq
Author URI: https://abdussamad.com/archives/567-Fixing-the-WordPress-Email-Return-Path-Header.html
*/
class email_return_path {
function __construct() {
add_action( 'phpmailer_init', array( $this, 'fix' ) );
}
@jnicol
jnicol / stop-video.js
Last active February 26, 2023 07:13 — forked from cferdinandi/stop-video.js
A simple method to stop YouTube, Vimeo, and HTML5 videos from playing.
View stop-video.js
/**
* Stop all iframes or HTML5 <video>'s from playing
*/
var stopVideos = function () {
var videos = document.querySelectorAll('iframe, video');
Array.prototype.forEach.call(videos, function (video) {
if (video.tagName.toLowerCase() === 'video') {
video.pause();
} else {
var src = video.src;
@jnicol
jnicol / copy-to-clipboard.js
Created February 23, 2022 23:20
Copy to clipboard
View copy-to-clipboard.js
function copyToClipboard() {
const cb = navigator.clipboard;
const el = document.getElementById('my-element');
cb.writeText(el.innerText);
}
View flush-lists.css
/* source: https://stackoverflow.com/a/43763137/315045 */
ol, ul {
padding-left: 0;
}
li {
list-style: none;
padding-left: 1.25rem;
position: relative;
@jnicol
jnicol / polyfills.html
Created March 20, 2020 01:05
polyfill.io for old browsers only
View polyfills.html
<!--
Only load polyfills for old browsers
@see https://devhints.io/polyfill.io
@see https://polyfill.io
-->
<script>if(!(window.Promise&&[].includes&&Object.assign&&window.Map)){document.write('<script src="https://cdn.polyfill.io/v3/polyfill.min.js"></scr'+'ipt>')}</script>
<!-- Same as above, but also loads Fetch API polyfill -->
<script>if(!(window.fetch&&window.Promise&&[].includes&&Object.assign&&window.Map)){document.write('<script src="https://cdn.polyfill.io/v3/polyfill.min.js?features=default,fetch"></scr'+'ipt>')}</script>
@jnicol
jnicol / remove-wp-image-sizes.php
Last active November 18, 2020 21:52
Remove WordPress default image sizes to save disk space
View remove-wp-image-sizes.php
<?php
function remove_default_image_sizes( $sizes) {
// sizes defined in media settings
unset( $sizes['thumbnail']);
unset( $sizes['medium']);
unset( $sizes['large']);
// auto-generated images since WP 5.3
unset( $sizes['medium_large']);
unset( $sizes['1536x1536']);
unset( $sizes['2048x2048']);
@jnicol
jnicol / wp-menu-no-ul.php
Created April 8, 2019 01:53
No <ul> or container for a WordPress menu. Useful if you want to manually add <li>'s to your menu.
View wp-menu-no-ul.php
<?php
wp_nav_menu( array(
'theme_location' => 'my-theme-location',
'depth' => 1,
'container' => '',
'container_class' => '',
'menu_class' => '',
'items_wrap' => '%3$s'
));
?>
@jnicol
jnicol / block-editor-scripts.js
Last active January 18, 2024 16:00
Register/unregister WordPress Gutenberg block styles
View block-editor-scripts.js
/**
* Scripts to run when in WordPress Gutenberg editor
*
* Unregister any block styles we don't want user to be able to select
* or register our own custom block styles.
*/
wp.domReady( () => {
// Unregister any block styles we don't want user to be able to select
wp.blocks.unregisterBlockStyle( 'core/quote', 'default' );
wp.blocks.unregisterBlockStyle( 'core/quote', 'large' );
@jnicol
jnicol / menu-hover.js
Last active February 25, 2019 23:56
Open/close a dropdown menu on hover.
View menu-hover.js
/**
* Open/close a dropdown menu on hover.
*
* The menu does not need to be a child or sibling of the button, but there should be no gap
* on screen between the bottom of the button and the top of the menu.
*
* The menu will remain open until the user's mouse leaves both the menu and button.
*
* Requires jQuery.
*/