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 / wp-api-timeouts.php
Last active Jan 23, 2018
Prevent `api.wordpress.org` requests timeouts: "Warning: An unexpected error occurred. Something may be wrong with WordPress.org or this server's configuration. If you continue to have problems, please try the support forums. (WordPress could not establish a secure connection to WordPress.org.)"
View wp-api-timeouts.php
<?php
// increase `timeout` for `api.wordpress.org` requests
add_filter( 'http_request_args', function( $request, $url ) {
if ( strpos( $url, '://api.wordpress.org/' ) !== false ) {
$request[ 'timeout' ] = 15;
}
return $request;
@tillkruss
tillkruss / w3tc-minify-cache-buster.php
Created Aug 12, 2014
add query string cache buster to stylesheets minified by W3 Total Cache
View w3tc-minify-cache-buster.php
<?php
// add query string cache buster to W3TC minified stylesheet links
add_action( 'init', function() {
// is css minify enabled?
if ( isset( $GLOBALS[ '_w3tc_ob_callbacks' ][ 'minify' ] ) && $GLOBALS[ '_w3tc_ob_callbacks' ][ 'minify' ][0]->_config->get_cache_option( 'minify.css.enable' ) ) {
// store original minify callback
$GLOBALS[ '_w3tc_ob_callbacks' ][ 'minify-org' ] = $GLOBALS[ '_w3tc_ob_callbacks' ][ 'minify' ];
@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-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();
}
View keybase.md

Keybase proof

I hereby claim:

  • I am tillkruss on github.
  • I am tillkruss (https://keybase.io/tillkruss) on keybase.
  • I have a public key whose fingerprint is 6490 DEB6 8D18 F0A3 49BD CB9C 8874 10C6 42BC 23BB

To claim this, I am signing this object:

@tillkruss
tillkruss / redis-test.php
Last active Aug 20, 2016
[WordPress] Redis Test MU-Plugin
View redis-test.php
<?php
/*
Plugin Name: Redis Test
Plugin URI: https://wordpress.org/plugins/redis-cache/
Description: Redis connection test.
Author: Till Krüss
Version: 1.0
Author URI: https://till.im/
*/
@tillkruss
tillkruss / Database.php
Last active Mar 4, 2016
[Laravel 5.1] Use Redis PECL/HHVM extension
View Database.php
<?php
namespace App\Redis;
use Redis;
use Illuminate\Redis\Database as RedisDatabase;
use Illuminate\Contracts\Redis\Database as DatabaseContract;
class Database extends RedisDatabase implements DatabaseContract
{
@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 / 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