WP-Mix

A fresh mix of code snippets and tutorials

Set Timeout and Redirect with JavaScript

Hello again! This WP-Mix tutorial shows how to set a timeout and redirect to any URL using vanilla JavaScript. It’s one line of code easy peasy.

jQuery: Remove parent element containing empty span

This tutorial explains how to remove the parent of an element that contains an empty <span></span> (or any empty element). First I’ll explain where it might be useful, and then share the magical code to make it happen.

WordPress Trigger 404.php Template

Recently I needed a programmatic way to trigger a 404 error in one of my free WordPress plugins. Fortunately WordPress makes it very easy to do. This quick tutorial explains two different ways to make it happen.

WordPress pre_get_posts example

Here is a quick example showing how to modify the main WP Query (Loop) using the pre_get_posts filter hook.

Mac Terminal Change to Directory on External Drive

Here is how to cd (change directory) into an external drive using Terminal on Mac computers. The trick is knowing the name of the drive and where it is located. On Macs, all connected drives (including hidden drives) are mounted/located under the /Volumes directory. So we can use this information to get the names of […]

Secure WordPress Login Page

If you try to log in to some of my WordPress-powered sites via the WP Login Page, you will be met with a 403 “Forbidden” response. For sites where I am the only registered user, I lock things down to prevent endless waves of drip force attacks. It really helps to reduce server load, conserve […]

Block BLEXBot via Apache/.htaccess

One of the worst bots I’ve encountered in a long time. BLEXBot likes to hit the same resources periodically and repeatedly. So it requests the same resources again and again, even if they are expressly forbidden via robots.txt or other methods. It’s like BLEXBot has no memory of where it’s been or what it’s doing. […]

Fix Database Won’t Start Error for MAMP Pro

I use MAMP Pro for some of my local pet projects and development. Normally it works great, but the other day I couldn’t get MySQL started. It kept crashing during startup. This post explains the related errors and how I managed to resolve the issue and get MAMP working again.

Find Password Protected Posts in the WordPress Database

Recently I needed to view all posts that were password-protected. Not finding a WordPress function for this, I wrote a quick SQL command to find all password-protected posts in the WordPress database.

Apache Require HTTP 1.1 for POST Requests

A reader recently asked how to limit POST requests to only HTTP 1.1. Well here is an .htaccess snippet that will do it.

Change Database Type to InnoDB or MyISAM

Originally, the WordPress database was formatted as type MyISAM. Then years later they changed the database format to InnoDB. Reportedly, InnoDB is superior to MyISAM in several ways. This is true for any dynamic site, not just WordPress. If your database is not InnoDB, you may benefit from changing it. This quick tutorial explains how […]

Remove All Matching Options from the WordPress Database

Typically when you want to remove an option from the WordPress database, you can use a function like delete_option(). But there are cases where such functions are insufficient. For example, in a previous version of my plugin Blackhole for Bad Bots, a database option is added for each blocked request, and each option name includes […]