Wordpress Sitemaps: disable, remove users, add lastmod

Wordpress 5.5 shipped with sitemaps enabled by default.  This quite possibly isn’t a good thing. Disable them entirely add_filter( ‘wp_sitemaps_enabled’, ‘__return_false’ ); Disable just the Users sitemap add_filter( ‘wp_sitemaps_add_provider’, function( $prov, $name ) { return ‘users’ === $name ? false : $prov; }, 10, 2 ); <lastmod> If you do want them, you may want […]

Remove URL slug from custom post type

Two functions, first one removes the slug from links throughout the site. Second one adds the custom post type to the query, so that it looks for the name in both regular posts and custom post type. function remove_cpt_slug( $link, $post ) { if ( ‘my_post_type’ === $post->post_type ) { $link = str_replace( ‘/’ . […]

Redirect entire site to a new domain with apache rewrite

Just put one of these rultes at the top of your .htaccess file. Pick your favorite. RedirectMatch 301 ^(.*) https://newdomain.com$1 RewriteRule ^(.*) https://newdomain.com$1 [R=301,L] RewriteRule ^ https://newdomain.com%{REQUEST_URI} [R=301,L] If you still want access to something (say adminer so you can check on the old database and to last minute stuff) use a RewriteRule method and […]

Wordpress logs you out at inconvenient times

It’s annoying to be signed out in the middle of your work. The default keeps you logged in for 2 weeks, and a lot of suggestions for changing this time use a multiple of 24 hours… so you’re always trapped in a cycle of getting logged out during working hours. (Say you log in monday […]

Quickly get rewrite rules for all wordpress posts

Run this SQL command (using adminer or whatever) and you’ll get a list of mod_rewrite rules ready to paste into your .htaccess file. SELECT CONCAT(‘RewriteRule ^’, post_name, ‘ https://yoururl.com/’, post_name, ‘/ [R=301,L]’) as ‘RewriteEngine On’ FROM `wp_posts` WHERE `post_type` = ‘post’ AND `post_status` = ‘publish’ ORDER BY `post_name` Change ‘post’ to ‘page’ if you want […]

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

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