Skip to content

Instantly share code, notes, and snippets.

@lumpysimon
lumpysimon / dequeue-wordpress-block-library-styles.php
Last active January 4, 2019 12:11
Dequeue the WordPress block editor stylesheet if the Classic Editor plugin is activated and configured
add_action( 'wp_enqueue_scripts', 'simon_dequeue_block_editor_styles' );
function simon_dequeue_block_editor_styles() {
if ( 'classic' === get_option( 'classic-editor-replace' ) ) {
wp_dequeue_style( 'wp-block-library' );
}
}
@lumpysimon
lumpysimon / limit-checkboxes.js
Created June 16, 2019 08:44
jQuery snippet to limit how many checkboxes can be checked
$( '.things' ).click( function() {
var bol = $( '.things:checked' ).length >= 8;
$( '.things' ).not( ':checked' ).attr( 'disabled', bol );
});
// from http://stackoverflow.com/questions/2966382/limit-checkbox-amount
@lumpysimon
lumpysimon / delete-spam-comment.sql
Created June 16, 2019 09:00
MySQL commands to delete spam WordPress comments & commentmeta
delete from wp_comments where comment_approved='spam';
delete from wp_commentmeta where comment_id not in (select comment_id from wp_comments);
delete from wp_commentmeta where meta_key like '%akismet%';
@lumpysimon
lumpysimon / .htaccess
Created June 16, 2019 09:01
.htaccess short WordPress URLs
# e.g. https://example.org/go/76
RewriteEngine On
RewriteRule ^go/([0-9]+)$ ?p=$1 [R=301,L]
@lumpysimon
lumpysimon / logging.php
Last active October 27, 2020 16:01
A simple logging class
<?php
namespace Simon\Src\Log;
// How to use this class:
//
@lumpysimon
lumpysimon / searchwp-exclude-spam.php
Last active July 6, 2021 20:01
Exclude spammy searches from SearchWP
add_filter( 'searchwp\statistics\log', 'my_log_filter', 10, 2 );
function my_log_filter( $enabled, $query ) {
$search_string = $query->get_keywords();
$long = ( strlen( $search_string ) > 30 );
$www = ( 'www' === substr( $search_string, 0, 3 ) );
$slashes = ( false !== strpos( $search_string, '/' ) );
if ( $long or $www or $slashes ) {
@lumpysimon
lumpysimon / aspect-ratio.css
Created February 22, 2021 14:44
aspect ratios in CSS
[style*="--aspect-ratio"] {
aspect-ratio: var(--aspect-ratio);
object-fit: cover;
}
@supports not (aspect-ratio) {
[style*="--aspect-ratio"] {
position: relative;
}
[style*="--aspect-ratio"]::before {