Add Media for Contributors

function add_theme_caps() { $trans = ‘1’; if ( get_transient(‘update_entries’ ) === $trans ) return; set_transient( ‘update_entries’, $trans, 1e5 ); $role = get_role(‘contributor’); $role->add_cap(‘upload_files’); } add_action( ‘admin_init’, ‘add_theme_caps’);

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 […]

Incremental and Random Key Code Generator

function readycat_keygen( $atts ) {          extract( shortcode_atts(         array(             ‘len’ => null,             ‘char’ => ‘ABCDEFGHJKMNPQRSTUVWXYZ23456789’,// don’t bother with I L 1 O or 0             ‘type’ => ‘count’,             ‘countby’ => null,             ‘pre’ => null,            […]

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 […]

Various WordPress Login and Access Management Snippets

// Hide admin toolbar on front-end from anyone without the ‘manage_options’ capability add_filter(‘show_admin_bar’, function($bool){ return current_user_can(‘manage_options’) ? $bool : false; }); function redirect_to_login_page_from_anywhere() { if ( is_user_logged_in() ) return; if ( empty($_SERVER[‘REQUEST_URI’]) || ‘/’ === $_SERVER[‘REQUEST_URI’] ) { $redirect = ”; } else { $redirect = ( is_ssl() ? ‘https://’ : ‘http://’ ) . $_SERVER[‘HTTP_HOST’] […]

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 […]

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 […]

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>    […]

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 + […]