WP-Mix

A fresh mix of code snippets and tutorials

Popular Posts

All posts ordered by popularity

Page 6 of 36

Block XSS with .htaccess

Quick snippet today that you can add to your .htaccess file to block some common XSS (cross-site scripting) attacks.

Add Defer and Async to WordPress Enqueued Scripts

When adding JavaScript in WordPress, it sometimes is necessary to add attributes such as async and defer to the <script></script> tag. Here is a technique to do it with any WordPress version 4.1 and better.

Display all images attached to post

Another technique for working with WordPress attachments, here’s how to display all images that are attached to the post, either before or after the existing post content.

WordPress Do Stuff on First User Login

Here is a code snippet that runs the first time a user logs in to their registered account. Useful for sending custom welcome emails, or whatever.

PHP Compress CSS & JavaScript

Quick snippets for compressing CSS and JavaScript with PHP’s ob_gzhandler, which will gzip or deflate content depending on browser support.

WordPress Exclude Custom Post Type from Search

Out of the box, WordPress search results include matches from any Custom Post Types that may be enabled via the theme template. For example, at htaccessbook.com, any matching content found in forum posts will be included in search results. This default behavior can be super convenient, but it is not always desirable. In this quick […]

Require user login for any plugin

Here’s a quick trick to require user-login for any plugin. For example, if you want users to be able to use your chat plugin only if they are logged in. Here’s how..

Including Arrays in URI Requests

Some esoteric code phenomena for you today.. in this post I explain how PHP handles arrays when they are included in URL requests (via the query string). It’s something I failed to grasp until doing some in-depth work developing my professional WordPress firewall plugin. Now let’s jump in..

PHP Sanitize XSS

Here is a simple PHP function I use to prevent XSS attacks. Use it to sanitize any user-input or otherwise unknown variables before use.

PHP Sanitize Form Data

On the Web, Cross-Site Scripting (XSS) is one of the most common types of attacks. Fortunately, there is an easy fix: always filter input data and always escape output data.

WordPress Get the Author Outside Loop

This tutorial explains how to get the current Post Author outside of the WordPress Loop.

Add links to HTML/CSS Validator

Here are some notes and markup examples for adding links to the W3C’s online HTML and CSS validators. This will enable your visitors to check any page on your site.