wordpress tips & tricks
Just a place to keep some of the common WordPress snippets that come in handy time and time again, some are mine, some are from other helpful people in the WordPress world.
.htacess Snippets
# Force SSL redirect
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]# Disable directory browsing
Options All -Indexes
# Deny access to wp-config.php file
# Remove Spaces before files
< files wp-config.php>
order allow,deny
deny from all
< /files>
# Prevent WordPress Username Enumeration
RewriteCond %{REQUEST_URI} !^/wp-admin [NC]
RewriteCond %{QUERY_STRING} ^author=\d+ [NC,OR]
RewriteCond %{QUERY_STRING} ^author=\{num
RewriteRule ^ - [L,R=403]
# Additional Security Headers for HSTS Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" env=HTTPS Header set X-XSS-Protection "1; mode=block" Header set X-Content-Type-Options nosniff Header always append X-Frame-Options SAMEORIGIN Header Referrer-Policy: no-referrer-when-downgrade
# Redirect Entire Old Domain to New
RewriteEngine on
RewriteCond %{HTTP_HOST} ^OLD.com.au$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.OLD.com.au [NC]
RewriteRule ^(.*)$ https://NEW.com.au/$1 [R=301,L]MYSQL/Maria DB
Run the scrip below in phpmyadmin -> SQL (change name of your db)
Copy the output and run that to convert
SET @DATABASE_NAME = 'name_of_your_db';
SELECT CONCAT('ALTER TABLE `', table_name, '` ENGINE=InnoDB;') AS sql_statements
FROM information_schema.tables AS tb
WHERE table_schema = @DATABASE_NAME
AND `ENGINE` = 'MyISAM'
AND `TABLE_TYPE` = 'BASE TABLE'
ORDER BY table_name DESC;
functions.php Snippets
Remove Yoast HTML Comments – Paul Collett
// Remove All Yoast HTML Comments
// https://gist.github.com/paulcollett/4c81c4f6eb85334ba076
add_action('wp_head',function() { ob_start(function($o) {
return preg_replace('/^\n?\n?$/mi','',$o);
}); },~PHP_INT_MAX);