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

VS Code doesn’t select the $$$

When using Microsoft Visual Studio Code / Monaco for PHP it’s really annoying to me how double-clicking a variable doesn’t include the dollar sign in the selection. Go to the settings and search for editor.wordSeparators: Word Separators Characters that will be used as word separators when doing word related navigations or operations. You can simply […]

Add a spinner to a submit button for slow forms

If you have a form that is slow to submit, this is a simple way to replace the submit button with a spinner. You may need to change the two selectors in the Javascript to be more specific, or different. Border-color may also want to be different, that’s the color of the spinner. <script>document.querySelector(‘form’).addEventListener(‘submit’,function(){ document.querySelector(‘[type=submit]’).className+=’ […]

Delete Wordpress post revisions older than x days

Delete post revisions older than 10 days: DELETE FROM wp_posts WHERE post_type = ‘revision’ AND post_modified_gmt < DATE_SUB(NOW(), INTERVAL 10 DAY) Delete post revisions older than 2 months: DELETE FROM wp_posts WHERE post_type = 'revision' AND post_modified_gmt < DATE_SUB(NOW(), INTERVAL 2 MONTH)

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

Creating an Administrator Account on WordPress using MySQL

If you need to quickly create an admin account for a WordPress site, upload adminer.php to the root directory or log in to phpMyAdmin, and run this SQL command (SQL tab in phpMyAdmin): INSERT INTO `DATABASE_NAME`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES (‘99999’, ‘username’, MD5(‘MakeABetterPassword’), ‘username’, ’email@gmail.com’, ”, NOW(), ”, […]