Author Archives: Patrick McGoohan

Simple vertical alignment for text

It’s not often that I miss tables but when I have to center something vertically I definitely find myself getting wistful for good ole VALIGN. There are lots of different ways of handling vertical centering, depending on what’s being centered. The method for centering a single line of text is, by far, the simplest. The […]

Can an element ID name start with a number?

Nope — Class identifiers can start with a number but IDs cannot. If, for whatever reason, you absolutely need to use a number to start the name of an ID, you can reference it in your stylesheet like you would a role or rel: <style> /* style reference for an element with ID of “1st”: […]

Padding full-width divs without overflow

The rule: One should not assign width and padding to the same element. Why not? Because display width of an element is equal to the assigned width plus any padding. A DIV that’s 100% wide with 10px padding is actually 100% + 20px wide. Put this element on your page and you’ll wind up with […]

Pixels to REM calculator

The default WordPress theme Twenty Sixteen is clean, simple, and responsive; as such it makes a perfect “starter” theme for all but the most arcane designs. However, it uses REM — a.k.a. relative em units — for the all the measurements and sizing in its stylesheet and, unfortunately, unless one is a genius, REMs have […]

jQuery’s noConflict Mode

It’s easy to take jQuery’s claim on “$” for granted. Pretty much every plugin or tutorial one can find online assumes “$” maps to the jQuery object. And, most of the time, one can code with this assumption and everything will work out fine. Every once in a while though, you write your Javascript, paste […]

Image Path in CSS File

Image paths are relative to the CSS file that contains them. If, for example, you had your images and css files each in their own subdirectories within the theme (i.e. “img/” and “css/”, respectively), here’s the path one would use: .navigation { background-image: url(../img/navigation.png); }

Disabling Comments on Posts and Pages

By default commenting is enabled on both Posts and Pages in WordPress. Here’s how to disable it: Existing Posts Click Posts in the left navigation. Click the checkbox in the section header (to the left of Title) to select all pages. Select Edit from the Bulk Actions dropdown and click the Apply button. Select Do […]

Strip all non-alphanumeric characters from a string

Here’s a very handy little snippet for stripping all non-alphanumeric characters from a string: $string = preg_replace(“/[^A-Za-z0-9]/”, “”, $string); This will leave all letters (whether they are capitalized or lowercase) as well as numbers 0 through 9.

Using SELECT in a MySQL INSERT Command

I wrote recently about using JOIN when needing to incorporate a lookup in a MySQL delete command. What if one needs to do the same when inserting into a table instead? This time it’s SELECT to the rescue. Imagine we have a simple bookmarking function that stores a user id and article id in a […]

Using JOIN in a MySQL DELETE Command

Deleting from a table is simple enough. If, for example, we wanted to remove all the comments from a single user and we already know that user’s id we could run this command (employing the EasyPDO library in PHP): <?php $db->ExecuteSQL(“DELETE FROM comments WHERE user_id=?”,”i”,$id); ?> Now imagine we only have the user’s email and […]