Prevent SVG from Overflowing Div Container

April 13, 2020

Steps to prevent an SVG from overflowing its div container: On the element, remove the inline and attributes, if present. On the…

Delete Transients with prefix in WordPress

February 27, 2020

Often in WordPress development, you need to save transients to the database that have dynamic names, like this: This results in dynamically…

JavaScript Array Filter to get Indices

September 16, 2019

JavaScript’s array method is awesome for pulling out just the values that you want. What if instead of getting those values though, you…

How to Add an AdSense ads.txt file to a Gatsby site

July 08, 2019

If you have a site built on Gatsby.js and have received a notification that you need to add an file to the root of the site, this is how…

When do WordPress Unit Tests Run (At Which Hook?)

June 27, 2019

Writing unit tests for a WordPress plugin recently had me wondering: When do WordPress unit tests run? Meaning, at what point during the…

get_post_author() by Post ID in WordPress

June 23, 2019

WordPress doesn’t have a native function you can call to get the user ID for the author of a post. This function can be used for that…

Find All Pages that Contain a Gravity Form

March 29, 2019

The class below can be used to locate all the pages that contain a specific Gravity Form. It searches the post content of each page. If the…

WordPress User Query Not Working with AJAX/WP-Cron

March 05, 2019

Recently, I was trying to do a user query on a WordPress site, but found that the query wasn’t able to fetch the users I wanted it to. This…

Get a list of all WordPress Pages that Contain a Shortcode

March 04, 2019

The function below can be used to get a list of all WordPress pages that contain a shortcode. You can use it like this: , replacing with…

PHP: Make an Array of Objects Unique By Comparing a Property

February 02, 2019

If you have an indexed array of objects, and you want to remove duplicates by comparing a specific property in each object, a function like…

Get all Gravity Forms with CSS Class

January 20, 2019

The functions below can be used to get a list of all Gravity Forms whose fields have a specific CSS class: Calling the first function looks…

Get All Super Admin Users in WordPress

January 07, 2019

WordPress’ function can be used to get the logins for all the users on the current site. Its return value is in array that looks like…

Get a List of the Beaver Builder Modules on a Page

September 26, 2018

I’ve been doing some work lately with the Beaver Builder page builder for WordPress. For one feature, I needed to get a list of all the…

Override WordPress REST API Callbacks for Protected Pages or Posts

July 07, 2018

I was recently working on a headless WordPress project. It has a React frontend that uses the WP REST API to communicate with the WP backend…

Check if a Remote Image File Exists in WordPress

June 27, 2018

If you want to check if a remote image file exists on a WordPress site but don’t necessarily want to fetch or download that file, this…

Get Term Being Edited on term.php WordPress Admin Page

April 03, 2018

The function below can be used for getting the object for the term that’s currently being edited on the page in the WordPress admin…

Get Menu Modified Date in WordPress

February 23, 2018

WordPress doesn’t store a last modified date for navigation menus, so I created the set of functions below for keeping track of when menus…

Download and Insert a Remote Image File into the WordPress Media Library

February 21, 2018

I built the following class that downloads a remote image, moves it into the /uploads/ directory of your site, adds it to WordPress as a new…

How to Transfer WordPress.org Plugin Ownership/Committers

July 26, 2017

To transfer WordPress.org plugin ownership to someone else: Update the plugin’s file, changing the , and in the plugin header and…

Advanced Custom Fields wysiwyg Toolbar Buttons Missing

June 29, 2017

If you notice that a site has Advanced Custom Fields wysiwyg toolbar buttons missing, it is likely because the toolbar is being displayed…

Get Uploads Directory Path in WordPress

April 21, 2017

The following function can be used to get the absolute path to the WordPress uploads directory: It will return a path to where the WordPress…

Get the Slugs for All Fields in an Advanced Custom Fields Flexible Content Field

April 19, 2017

The following function can be used to get the slugs of all fields in an Advanced Custom Fields flexible content field. By default, it…

Include Featured Images with Posts Using WordPress Export/Import Tool

February 08, 2017

When you use the basic WordPress XML Export/Import tool to migrate blog posts between two WordPress sites, their featured images will likely…

Get All WooCommerce Order Notes

November 17, 2016

I’ve seen posts and documentation online for how to get just the customer notes for an order, but no great ones for how to get all…

Add unfiltered_html Capability to Admins or Editors in WordPress Multisite

September 13, 2016

Per this Trac ticket , WP intentionally disallows adding the ‘unfiltered_html’ capability to any non-Super Admin users on the WordPress…

Edit Slug Button Missing in WordPress

September 12, 2016

If somewhere in the code for a WordPress site there is a filter hooked to that’s replacing the URL so that it no longer contains the…

Save Gravity Forms File Upload to Advanced Custom Fields Field in WordPress

September 09, 2016

Using the Gravity Forms + Custom Post Types WordPress plugin to map your Gravity-Forms-generated posts to a custom post type is very handy…

Get File Type by URL for a Remote File in WordPress

September 08, 2016

If you want to get the file mime type for a remote file and you have its URL, the function below can be used. Example If the remote file is…

Get the Excerpt by Post ID in WordPress

September 06, 2016

The entry in the WordPress Codex says that it returns “…either a user-supplied excerpt, that is returned unchanged, or an automatically…

Get User’s First and Last Name in WordPress

August 31, 2016

The function below can be used to get a user’s first and last name with a space between them, like “Kellen Mace”. If they only have a first…

Check if User Exists by ID in WordPress

August 26, 2016

WordPress has a built in function to check if a user exists by their username, but there isn’t a similar function for checking if a user…

Get Root Domain of a WordPress Multisite Network

August 19, 2016

The functions below can be used to get the root domain of a WordPress site. If the site is a multisite network and you’re on , calling…

Get Main Site URL in WordPress Multisite Network

August 19, 2016

The code below can be used to get the URL of the main site in the WordPress Multisite Network:

Disable CMB2 Styles on Front End Forms

August 17, 2016

CMB2 comes with default styles, but you may want to disable them if you’re outputting forms on the front end so they can be styled to match…

Get URL to a User’s BuddyPress Activity Stream Page

July 23, 2016

If the BuddyPress activity stream component is enabled, the tab showing the activity stream is typically accessible at the main user…

Get Post Types by Taxonomy in WordPress

June 16, 2016

The code below can be used to get the post types for a taxonomy in WordPress. This is useful if you know the taxonomy and want to get the…

Remove Line Breaks in WordPress

June 02, 2016

In the WordPress editor, lines that have a line break at the end of them will be turned into an HTML line break tag then they are output…

WP-CLI search-replace Tables Skipped

May 24, 2016

WP-CLI ‘s command is invaluable for changing all the URLs from a production or staging site to reflect your local development environment…

Get Blog Posts Page URL (Permalink) in WordPress

May 20, 2016

To get the URL (permalink) to the main blog posts page, you can use the function below. It will return the blog posts page URL whether the…

Advanced Custom Fields Metabox Priority for Top, Above Publish

May 11, 2016

By default, all Advanced Custom Fields metaboxes with a position/context of “side” are given a priority of “core” which means that they’ll…

Copy Media File From One Site to Another Within a Multisite Network

May 05, 2016

This class shows how to copy a file from one site to other sites within the same WordPress multisite network. This code uses to copy the…

Get User’s Capabilities in WordPress

May 05, 2016

The function below can be used to get all of a user’s capabilities: If you pass a user ID to it, you will get that user’s capabilities. If…

Get Page Template for Post in WordPress Admin

May 05, 2016

You can get the filename of the page template that the post in the WordPress admin is set to using: The function below gets the filename of…

WordPress Hook After Options Page Save

April 28, 2016

If you want to hook into WordPress when an options page is saved and access the values that were entered, you can use . Let’s say for my…

Get the ID of the Main Site in a WordPress Multisite Network

April 05, 2016

Here’s how you can get the ID of the main site in a WordPress multisite network. This can be useful for switching to that blog using to…

Change featured image title and link text in WordPress

April 01, 2016

Update for WordPress 4.3+ As of WordPress 4.3, you can set the , , and labels to whatever custom text you’d like to use instead. You…

Set Image Caption via PHP in WordPress

March 22, 2016

In order to change an image’s caption, you can of course find that image in the WordPress Media Gallery and enter a new value in the field…

Set Up SSL Locally on VVV/Vagrant WordPress Site

January 03, 2016

This post covers how to set up a local SSL WordPress site. These instructions assume you’re on a Mac and use Varying Vagrant Vagrants (VVV…

Get Current User’s Role in WordPress

January 02, 2016

There’s no WordPress function to directly get the current user’s role, so I typically include my own function to serve that purpose, similar…

Load Template From WordPress Plugin

December 11, 2015

You can load a template file from your plugin using the filter, with code similar to this: If you’re looking for something more robust…

Download a Plugin or Theme from the WordPress Admin Dashboard

December 02, 2015

Typically, if I need to download a plugin or theme that’s running on a remote server, I connect to that server via FTP or SSH and transfer…

Display WooThemes Testimonials Avatar before Quote

November 03, 2015

By default, the WooThemes Testimonials WordPress plugin displays the quote, then the avatar (author’s image), then the attribution (name…

Bundle Load Testing with a Project

September 29, 2015

If you need to be able to run load tests on a project, but don’t want each developer to have to install something like Siege on their own…

Clear Selectize Control on Dropdown Click

September 16, 2015

If you’re using Selectize to power your dropdown menus, you may find yourself wishing that when the user clicks the dropdown menu, the…

Replace Post Meta Query with Taxonomy Query

September 06, 2015

In this post, I’ll cover how to replace a post meta query with a taxonomy query. Why, you ask? WordPress’ postmeta database table is not…

Change WordPress Customizer Control Value Programmatically

September 03, 2015

Since the WordPress Customizer is built using the Underscore.js and Backbone.js libraries, the values of all the customizer controls are…

Rename Custom Post Type in WordPress

August 28, 2015

If you simply want to change how a post type is displayed in the WordPress admin, you can simply change its labels, or use a plugin like…

Set up PHP CodeSniffer in PhpStorm with WordPress Coding Standards

August 11, 2015

The steps below cover how to set up PHP CodeSniffer in PhpStorm with WordPress Coding Standards rulesets. This can be very helpful for…

Vagrant Not Reachable After Disconnecting from VPN

July 22, 2015

If Vagrant is not reachable after disconnecting from a VPN, first run these commands to bring the interface down, then back up: For a long…

Get Images from Remote Server by Proxy

July 17, 2015

If you have the files and database you need to work on a WordPress site locally but not the images and other media, how can you get them…

Get Permalink of Page Outside of The Loop

July 17, 2015

Let’s say you have some WordPress code that’s looping through all your posts and outputting some of their data to the webpage. How would you…

Create a Taxonomy Dropdown in WordPress

June 25, 2015

In this post, I’ll outline how to create a taxonomy dropdown in WordPress that lets the user choose an option, then reloads the page to only…

Require Post Title for Custom Post Type

June 23, 2015

In this post, I’ll outline how to make the post title field required for a custom post type in WordPress. By default, if a user leaves the…

Prepare WordPress Theme for SSL (https)

April 20, 2015

Moving your site to SSL is often a great idea for the obvious security purposes, but also for search engine optimization (SEO), since Google…

Force CSS & JS Changes to “go live” Immediately

April 08, 2015

To quote Mark Jaquith’s helpful post on this topic: If you update your WordPress theme’s style.css, you may have noticed that you have to…

Separate Trackpad & Mouse Natural Scrolling in Mac OS X

July 15, 2014

When using the trackpad on your computer, Apple’s “natural” scrolling feature is pretty great. The content moves in the same direction as…

Remove Custom Post Type Slug from Permalinks

May 28, 2014

Remove Custom Post Type Slug from Permalinks in WordPress easily with these two code snippets.

Remove Slug from Custom Post Type

May 28, 2014

Remove Slug from Custom Post Type URLs in WordPress