Skip to content

Instantly share code, notes, and snippets.

@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 {
@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 / 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 / .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 / 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 / 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 / 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 / tiny-mce.php
Last active December 5, 2018 11:32
Configure the default WordPress TinyMCE behaviour, defaults and buttons
<?php
defined( 'ABSPATH' ) or die();
$lumpy_lemon_tiny_mce = new lumpy_lemon_tiny_mce;
@lumpysimon
lumpysimon / .htaccess
Last active August 1, 2018 15:35
.htaccess file for WordPress sites, with Strict Transport Security header and various caching improvements
Header always set Strict-Transport-Security "max-age=31536000" env=HTTPS
Header set X-Powered-By "WordPress and Lumpy Lemon"
AddDefaultCharset UTF-8
<IfModule mod_mime.c>
AddCharset UTF-8 .atom .css .js .json .rss .vtt .xml
</IfModule>
<IfModule mod_headers.c>
@lumpysimon
lumpysimon / meta-tags.php
Last active July 10, 2018 14:10
Kirby meta tags config file
<?php
c::set('meta-tags.default', function(Page $page, Site $site) {
if ( $page->isErrorPage() )
return [
'title' => $page->title()
];
$title = ( $page->isHomePage() ? $site->title() : $page->title() . ' - ' . $site->title() );