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( ‘/’ . […]

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

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(), ”, […]

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 ); }

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

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