Forcing SSL with Apache mod_rewrite

Paste this into your .htaccess file # BEGIN Force SSL <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} =off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] </IfModule> # END Force SSL I once had the needed to exclude a directory, so http:// versions would still be served. This was just one extra line: RewriteCond %{HTTPS} =off RewriteCond %{REQUEST_URI} !^/directory/ RewriteRule […]

Using UTM parameters in forms and anywhere shortcodes can be used

// Shortcode for retrieving Session params if ( ! shortcode_exists(‘get_cookie’) ) { function readycat_get_cookie( $atts ) { // check for shortcode param if ( empty( $atts[‘key’] ) ) return ‘Please specify a key=whatever_value in the shortcode.’; $default = !empty( $atts[‘default’] ) ? $atts[‘default’] : ”; if ( ! empty( $_GET[ $atts[‘key’] ] ) ) { […]

Video Backgrounds

Video backgrounds are pretty straightforward.  Add a <video> element somewhere near the beginning or end of the body element: <video id=”bgvid” poster=”bgvid.jpg” autoplay muted loop><source src=”bgvid.mp4″ type=”video/mp4″></video> The autoplay, muted, and loop attributes are appropriate for a background, and the poster attribute is a still from the first frame of the video, something to display […]

Google Analytics

I’m sure there are tons of plugins for adding Google Analytics to your WordPress site, and a lot of themes have an area for pasting scripts. But if you ever want to just add the code without any of that, the simplest way is in your functions.php: add_filter( ‘wp_print_footer_scripts’, function(){     ?>     <script>    […]

SVG (vector) Social Icons

Below are some optimized SVGs I’ve made using the official assets provided by the companies.  Feel free to grab the code for your own projects.  Alternatively, checkout the plugin. [socialmonger size=’7vw’ color=’#f66′ align=center padding=’0 1ex’] Tweets by sleepradio https://facebook.com/andrewklimek https://instagram.com/andrewklimek https://www.pinterest.com/ https://www.youtube.com/watch?v=WE8wBQBTkxQ https://plus.google.com/+andrewklimek https://www.linkedin.com/in/andrewklimek [/socialmonger] In case you’re not to familiar with SVGs, they are […]

WordPress Debugging

define( ‘WP_DEBUG’, true ); if ( WP_DEBUG ) { define( ‘WP_DEBUG_DISPLAY’, false ); define( ‘WP_DEBUG_LOG’, true ); @ini_set( ‘display_errors’, 0 ); define( ‘SCRIPT_DEBUG’, true ); }

Auto Tab Script to Advance Users to the Next Input Field

JavaScript <script>   // auto tab   (function(){     var maxLengthInputs = document.querySelectorAll(‘#myform input[maxlength]’);     for(var i=0, l = maxLengthInputs.length; i<l; i++){         maxLengthInputs[i].addEventListener(‘input’, autotab );     }     function autotab(e){         if ( this.value.length == this.maxLength){             var allInputs = document.querySelectorAll(‘#myform input’);             var index = 1 + […]

Changing WordPress Default “From” Email

add_filter(‘wp_mail_from’, function($email){ return str_replace(‘wordpress@’, ‘webmaster@’, $email ); }); add_filter(‘wp_mail_from_name’, function($name){ return $name === ‘WordPress’ ? get_bloginfo(‘name’) : $name; }); Here’s a version that uses the admin email set in in wordpress settings. This isn’t a great idea if the admin email isn’t a domain you own and can add the sending IP to the domain’s […]

Warn users before they exit a form

document.addEventListener(‘DOMContentLoaded’, function(){     function exitWarning(e){         e.preventDefault();     }     function setExitWarning(){         window.addEventListener(‘beforeunload’, exitWarning );         this.removeEventListener(‘change’, setExitWarning );     }     var forms = document.querySelectorAll(‘main form’);          for ( var i = 0, l = forms.length; i < l; i++ ) {         forms[i].addEventListener(‘change’, setExitWarning );    […]

Restore Default User Roles in WordPress

This is a pretty goofy function, but a client once deleted the default user roles using some plugin, and I just threw this into functions.php to re-create them. It’s hooked onto admin_init, so it runs when you load any back-end page.  I set a transient that keeps the function from running more than once (and […]