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 ); }
ideas for faster & simpler websites
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 ); }
// 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’] […]
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 […]
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, […]
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 […]
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( ‘/’ . […]
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 […]
From the command line, navigate to the uploads folder and use this… but first try it without the -delete flag to make sure it looks right. find -type f -regex ‘.*-[0-9]+x[0-9]+.\(jpg\|png\|jpeg\|gif\)$’ -delete
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 […]