Skip to content

Instantly share code, notes, and snippets.

@tomhayes
tomhayes / functions.php
Created July 17, 2019 08:50
Add OS and Browser as body class in WordPress
<?php
function mv_browser_body_class($classes) {
global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
if($is_lynx) $classes[] = 'lynx';
elseif($is_gecko) $classes[] = 'gecko';
elseif($is_opera) $classes[] = 'opera';
elseif($is_NS4) $classes[] = 'ns4';
elseif($is_safari) $classes[] = 'safari';
elseif($is_chrome) $classes[] = 'chrome';
@tomhayes
tomhayes / docker-wordpress.sh
Created June 21, 2019 21:52 — forked from tatemz/docker-wordpress.sh
A quick way to get a WordPress installation up and running with Docker
#!/bin/bash
mkdir wordpress-site && cd wordpress-site
touch docker-compose.yml
cat > docker-compose.yml <<EOL
version: "2"
services:
my-wpdb:
@tomhayes
tomhayes / outlook-font.html
Created January 31, 2019 10:17
Fix font formatting issues in Outlook
<!--[if mso]>
<style type="text/css">
body, table, td {font-family: Arial, Helvetica, sans-serif !important;}
</style>
<![endif]-->
@tomhayes
tomhayes / drumseq
Last active April 10, 2019 22:14
Sonic Pi Drum Sequencer
#DRUM SEQUENCER
use_bpm 125
#PATTERNS (1=on, 0=off, 8 steps but add more if needed)
kickpattern = (bools 1,0,0,0,1,0,0,0)
snarepattern = (bools 0,0,0,1,0,0,1,0)
hatpattern = (bools 1,0,1,0,1,0,1,1)
#RESOLUTION (set step resolution in 0.25s)
seqres = 0.25
@tomhayes
tomhayes / enqueue-admin-stylesheet.php
Last active April 28, 2017 09:57
Enqueue stylesheet for admin area Add to functions.php
// Enqueue stylesheet for admin area
add_action( 'admin_enqueue_scripts', 'load_admin_style' );
function load_admin_style() {
wp_enqueue_style( 'admin_css', get_template_directory_uri() . '/admin.css', false, '1.0.0' );
}
@tomhayes
tomhayes / add-user-role-class-body.php
Last active April 28, 2017 09:58
Add user role as a class to body Add to functions.php
// Add user role as a class to body
if ( is_user_logged_in() ) {
add_filter('body_class','add_role_to_body');
add_filter('admin_body_class','add_role_to_body');
}
function add_role_to_body($classes) {
$current_user = new WP_User(get_current_user_id());
$user_role = array_shift($current_user->roles);
if (is_admin()) {
@tomhayes
tomhayes / wp-domain-migration.sql
Last active January 20, 2017 02:23
Update WordPress domains for migrating site (SQL)
SET @oldsite='http://oldsite.com';
SET @newsite='http://newsite.com';
UPDATE wp_options SET option_value = replace(option_value, @oldsite, @newsite) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, @oldsite, @newsite);
UPDATE wp_links SET link_url = replace(link_url, @oldsite, @newsite);
UPDATE wp_postmeta SET meta_value = replace(meta_value, @oldsite, @newsite);
/* only uncomment next line if you want all your current posts to post to RSS again as new */
#UPDATE wp_posts SET guid = replace(guid, @oldsite, @newsite);
@tomhayes
tomhayes / .htaccess
Last active January 20, 2017 02:30
301 Redirect (.htaccess)
Redirect 301 /old-page /new-page
@tomhayes
tomhayes / .htaccess
Last active January 20, 2017 02:31
Enable GZIP Compression (.htaccess)
<IfModule mod_deflate.c>
# Insert filters
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
@tomhayes
tomhayes / .htaccess
Last active January 20, 2017 02:31
Force www. (.htaccess)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^your-site.com [NC]
RewriteRule ^(.*)$ http://www.your-site.com/$1 [L,R=301]