Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Till Krüss tillkruss

🏠
Working from home
View GitHub Profile
@tillkruss
tillkruss / filename-based-cache-busting.php
Last active Jan 23, 2018
Filename-based cache busting for WordPress.
View filename-based-cache-busting.php
<?php
// changes CSS and JavaScript URLs from `css/style.css?ver=1.3.3.7` to `css/style.1.3.3.7.css`
if ( ! is_admin() ) {
foreach ( array( 'style_loader_src', 'script_loader_src' ) as $filter ) {
add_filter( $filter, function( $url ) {
// abort if `$url` doesn't start with `WP_CONTENT_URL`
@tillkruss
tillkruss / gist:4616592
Last active Dec 11, 2015
Force disable WordPress developer plugins in production environments. Depended on WP_STAGE constant. Use as MU plugin.
View gist:4616592
<?php
/*
Plugin Name: Disable Developer Plugins
Description: Force disables developer plugins in production environments.
*/
$dev_plugins = array(
'debug-bar/debug-bar.php',
'debug-bar-cron/debug-bar-cron.php',
'debug-bar-extender/debug-bar-extender.php',
@tillkruss
tillkruss / image-link-type.php
Last active Dec 22, 2017
Change default "image link" type in WordPress.
View image-link-type.php
@tillkruss
tillkruss / disable-feeds.php
Last active Dec 11, 2015
Disable all WordPress feeds.
View disable-feeds.php
<?php
add_action( 'do_feed_rdf', function() { wp_redirect( home_url(), 301 ); exit; }, 1);
add_action( 'do_feed_rss', function() { wp_redirect( home_url(), 301 ); exit; }, 1);
add_action( 'do_feed_rss2', function() { wp_redirect( home_url(), 301 ); exit; }, 1);
add_action( 'do_feed_atom', function() { wp_redirect( home_url(), 301 ); exit; }, 1);
add_action( 'init', function() {
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
});
@tillkruss
tillkruss / disable-search.php
Last active Jul 6, 2020
Disable WordPress front-end search functionality.
View disable-search.php
<?php
if ( ! is_admin() ) {
add_action( 'parse_query', function( $query ) {
if ( $query->is_search ) {
unset( $_GET['s'], $_POST['s'], $_REQUEST['s'] );
$query->set( 's', '' );
$query->is_search = false;
$query->set_404();
header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' );
@tillkruss
tillkruss / gist:5283503
Created Apr 1, 2013
Remove "tags" from WP's admin UI.
View gist:5283503
<?php
add_action( 'admin_menu', function() {
remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=post_tag' ); // Remove menu link under "Posts"
});
add_action( 'admin_menu', function() {
remove_meta_box( 'tagsdiv-post_tag', 'post', 'side'); // Remove metabox on add/edit post screen
});
add_filter( 'manage_posts_columns', function($columns) {
unset( $columns['tags'] ); // Remove "Tags" column in post listing
@tillkruss
tillkruss / paste-as-plain-text.php
Last active Jun 22, 2020
Force the WordPress editor to always paste as plain text.
View paste-as-plain-text.php
<?php
// always paste as plain text
foreach ( array( 'tiny_mce_before_init', 'teeny_mce_before_init') as $filter ) {
add_filter( $filter, function( $mceInit ) {
$mceInit[ 'paste_text_sticky' ] = true;
$mceInit[ 'paste_text_sticky_default' ] = true;
return $mceInit;
});
}
@tillkruss
tillkruss / disable-posts.php
Last active Dec 22, 2017
Disable front-end blog functionality in WordPress, including categories, author archives, etc.
View disable-posts.php
<?php
add_action( 'template_redirect', function() {
global $wp_query;
if ( is_home() || $wp_query->is_singular( 'post' ) || $wp_query->is_post_type_archive( 'post' ) ) {
header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' );
$wp_query->set_404();
}
@tillkruss
tillkruss / default-mp6-color-scheme.php
Last active Dec 22, 2015
Change the default MP6 admin color scheme.
View default-mp6-color-scheme.php
<?php
add_filter( 'get_user_option_admin_color', function( $color_scheme ) {
global $_wp_admin_css_colors;
if ( ! isset( $_wp_admin_css_colors[ $color_scheme ] ) ) {
$color_scheme = 'ectoplasm';
}
@tillkruss
tillkruss / force-color-scheme.php
Last active Jan 21, 2020
Enforce a specific WordPress admin color scheme.
View force-color-scheme.php
<?php
add_action( 'admin_init', function() {
// remove the color scheme picker
remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
// force all users to use the "Ectoplasm" color scheme
add_filter( 'get_user_option_admin_color', function() {
return 'ectoplasm';