WP-Mix

A fresh mix of code snippets and tutorials

Popular Posts

All posts ordered by popularity

Page 7 of 35

WordPress Get the Author Outside Loop

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

Protect files with .htaccess

Here are some examples of how to use .htaccess to protect any sensitive files on the server.

WordPress: Get All User Roles

WordPress makes it easy to get the current user’s role(s) by using wp_get_current_user(). But what if you want to get all roles from all users. Like a list of every role that is used on your site. Well good news, WordPress provides a global object named $wp_roles that provides the information. So if you’re looking […]

PHP Search Multidimensional Array

When you need to search an array using PHP, you can call upon the ancient powers of in_array() and call it a day. But that only works for flat, or one-dimensional arrays. What if you need to find a value in a multi-dimensional array? Well my friend, there isn’t a native PHP function to help […]

Remove .DS_Store in macOS

I would give my left testicle to stop macOS from creating .DS_Store files in every freaking directory on the system. The stupid files have been driving Mac users mad for years, and apparently there is no end in sight. Fortunately, there are a couple of ways to remove them.

Combine all CSS files with PHP

Here is a simple PHP script that will combine all CSS files (stylesheets) in a given directory. Delivering one CSS file with your web pages is much faster than delivering multiple files because there are fewer HTTP requests involved.

Display all comments on separate page

Normally WordPress themes display comments on the same post or page. WordPress makes it possible to page the comments, so that there are only so many per page, but by default it’s not possible to display all comments on a separate page. Here’s how to do it in three easy steps.

Disable manual resizing with meta viewport

Just a quick snippet for telling the browser to disable manual resizing of the page. You can see this technique in use here at WP-Mix as well as most of my other websites. If you view the source code of any web page on the site, you can see the meta viewport tag in effect […]

Disable extra p tags in WP shortcodes

When WordPress processes shortcodes, it first passes the content through its wpautop() function to convert line breaks to <p></p> or <br /> tags. This order of processing can lead to unwanted paragraph and breaks scattered throughout your shortcode content. This post provides a simple way to prevent this from happening, so you can keep your […]

Set PHP Limits with .htaccess

A quick summary of some of the PHP limits that can be set via the .htaccess file.

Display Images with User Submitted Posts

Here is a quick recipe for displaying linked images for images submitted with the User Submitted Posts plugin.

503 Service Unavailable Headers via .htaccess

Sending a few HTTP headers is a simple way to let visitors and search engines know that your site currently is unavailable. This is useful when you are doing maintenance and don’t need access to the front-end of your site. Simply add the rules to .htaccess when your site is down, and then remove them […]