WP-Mix

A fresh mix of code snippets and tutorials

Popular Posts

All posts ordered by popularity

Page 11 of 35

.htaccess for cookie-less image domain

Here is a choice collection of .htaccess directives that I use when hosting images on a subdomain. When doing so, it’s best for performance to make sure the domain or sub-domain is “cookie-less”, so there is no time wasted sending cookie data back and forth between the server and client. Other optimizations are included to […]

CSS box-sizing all elements

The CSS box-sizing property makes it much easier to work with elements that have padding and borders. Here is a ruleset that will apply the box-size property to all elements.

Redirect HTTP to PHP via .htaccess

Here is how to redirect specific URL requests to a PHP script for further processing, etc. Very useful for monitoring HTTP activity, logging errors, and more.

Recursively display images via PHP

Here is an easy way to display all images in a directory — including images contained in sub-directories.

WordPress Example Child Theme

Here is a ready-to-go example Child Theme that you can download and use on your own WordPress-powered site.

Replace contenteditable with textarea

Working on my WordPress plugin, Dashboard Widgets Suite, I needed a solid way of replacing contenteditable with a textarea on form submit. Here is a simple solution along with some bonus notes on dealing with certain HTML tags.

Break Out of Frames

This tutorial explains some ways to use JavaScript to prevent your pages from being framed. Also known as “frame busting” or “breaking out of frames”.

Combine & compress CSS files with PHP

Here is another technique for combining multiple CSS stylesheets into a single, compressed file.

PHP check if file exists by URL

This quick PHP snippet can be used to check if a specific URL exists. I use this in one of my projects for checking the existence of a robots.txt file on the site. Can be modified to check for files on any publicly accessible site.

Get the Current URL in WordPress

Quick tip: get the current URL in WordPress:

WordPress template_redirect Example

Quick code snippet showing basic use of the WordPress template_redirect action hook. This is provided as a quick copy/paste reference for WordPress developers. This hook is useful for customizing any functionality requiring full query information.

PHP Get Actual IP Address

Here are a couple of quick snippets to get the visitor’s actual IP address via PHP.