WordPress Snippets

PHP Error Fix: Uncaught ValueError: Unknown format specifier “S”

Here's a problem that I've seen a few times of late, especially since the introduction of PHP version 8 and higher.   WordPress sites using outdated themes are often showing errors in and around the site especially in the Dashboard, the specific error being: PHP [...]

WordPress Only Shows Homepage – Other Pages 404 Error

Is your WordPress website only showing the homepage and all other pages redirecting to a 404 page or error page? The issue can often happen after a WordPress update, or even a plugin update such as a security or redirection plugin.  Fortunately, the fix [...]

WordPress Shortcode to Get Text from URL Vars/Parameters

Sometimes you may have a URL that has parameters or variables included in it that you wish to display on a page or post within WordPress.  In cases like this all that's needed is a simple function to get the information from the URL onto [...]

WooCommerce: Select First Variation if it Exists

If your WooCommerce variations aren't user friendly for the user because it's always asking them to choose from a huge selection, or showing "Choose an option" or "Please select" text even if there's only one variation, a simple fix will help make your WordPress [...]

Critical Error on WordPress/Avada for PHP 7.2

Recently a client reached out concerning a critical error in WordPress using Avada when trying to access the wp-admin area of the website. It appears that the problem is due to an issue with Revolution Slider, specifically a metabox function that's including in the admin [...]

WooCommerce No Orders Found Problem

Since WordPress 5.0.2, many WooCommerce installations have had an issue where all the shop's products have seemingly disappeared. Don't worry, they're still there, but if your WooCommerce installation is showing "No orders found" in the Orders sections of your Dashboard, here's what you'll need to [...]

2018-12-20T15:51:44+00:00December 20th, 2018|Programming Tips, WordPress Snippets|4 Comments

Add a Custom Taxonomy Filter to WordPress Custom Post Type

Recently, a client needed to be able to filter their custom post type posts list by a given taxonomy, making it easier to find what they were looking for.   Fortunately with WordPress this isn't difficult. For the example below, the client was a restaurant who [...]

2018-11-07T01:02:32+00:00October 6th, 2018|Web Programming, WordPress Snippets|0 Comments

Gravity Forms Telephone Validation (UK Number with Maximum and Minimum Digits)

Recently a client needed a function or two for Gravity Forms to process UK telephone numbers, and asked that they are between 7 and 15 characters in length. The following Gravity forms filters do exactly what's needed. Paste them in to your theme's function.php [...]

WordPress Problem: Can Not Activate a Plugin

WordPress: Activating a Plugin Manually A client came to me recently with a broken site problem they simply couldn't fix. They had de-activated a plugin that was so heavily ingrained into the site that all site functionality had ceased to work, meaning they could not [...]

2018-11-07T01:03:39+00:00February 27th, 2018|Web Programming, WordPress Snippets|2 Comments

How to Remove the Connect your store to WooCommerce.com Message

After the recent WooCommerce updates, a number of clients have contacted me to ask about the admin message that appears in the WordPress Dashboard: Connect your store to WooCommerce.com to receive extensions updates and support. This message certainly isn't anything to be concerned about, and [...]

2021-09-11T01:47:27+00:00February 10th, 2018|WordPress Snippets|4 Comments

MySQL Fix: Error #1273 – Unknown collation: ‘utf8mb4_unicode_520_ci’

From time to time when migrating a WordPress website, you may come across collation issues when migrating the database. Specifically, a common error message when importing via PHPMyAdmin is the #1273 – Unknown collation: ‘utf8mb4_unicode_520_ci’ error. When Wordpress updated to version 4.2 they introduced support [...]

2018-11-07T01:05:20+00:00August 6th, 2017|WordPress Snippets|0 Comments

Restrict Dates to Future Only in Gravity Forms Datepicker

Gravity Forms is quite possibly the best forms plugin available for WordPress, but even with the vast array of functionality it offers right out of the box it still has its limitations. One such limitation is the date picker field, offers practically no chance of [...]

2020-09-25T23:45:06+00:00July 12th, 2017|WordPress Snippets|11 Comments

Change Howdy Welcome Message on WordPress Admin Bar

It's often the small things that tend to annoy us, and in the case of one client it was the "Howdy" message on the right of the WordPress admin bar. A small thing perhaps, but how can you change it, programmatically? Fortunately help is at [...]

2018-11-07T01:06:41+00:00July 7th, 2017|WordPress Snippets|2 Comments

Restrict WordPress Registration to Certain Email Domains

Recently for a project it was necessary to restrict WordPress registration to a select few specific domains, for example: domains with an email address from a certain company, i.e. email addresses ending with @warrenchandler.com. Rather than using a plugin to do limit domain access when registering, [...]

2019-03-13T01:32:49+00:00December 12th, 2016|WordPress Snippets|19 Comments

WooCommerce Product Unavailable Out of Stock Problem

UPDATE: On later versions of WooCommerce in 2020 you may also try the following fix for the 30 limit threshold. https://www.warrenchandler.com/2020/06/27/woocommerce-variations-break-after-30-or-more-bug-fix/ Recently, a client was reporting that they were seeing an out of stock message on their product page, which wasn't correct.  All of the [...]

2020-06-27T17:42:03+00:00November 8th, 2016|Web Programming, WordPress Snippets|17 Comments

WordPress Resize at Upload Plugin mysql_real_escape_string() Error

If like me you use the WordPress plugin Resize at Upload, or Resize at Upload Plus, it's quite likely that you'll be getting a mysql error when changing the settings.  Something like: Access denied for user ''@'localhost' (using password: NO) in /home/accountname/public_html/wp-content/plugins/resize-at-upload/resize-upload.php on line 63 [...]

2018-11-07T01:08:52+00:00June 26th, 2016|PHP Snippets, WordPress Snippets|1 Comment

WordPress Login Redirect For Different User Roles

From time to time clients come to me requesting login redirects in WordPress. The following handy snippet below allows you to specify where the user lands once they've logged in, based on user roles. In the example, users with Administrator and Editor roles are redirected [...]

2018-11-07T01:10:06+00:00August 29th, 2015|WordPress Snippets|0 Comments

WordPress Search Syntax in URL for Custom Post Types

WordPress isn't exactly Google when it comes to searching. The system is long overdue an overhaul, but while we wait for the never-arriving necessity you can still get much more out of your WordPress searches. Today a programmer client asked me something that I thought [...]

2018-02-02T03:09:31+00:00January 25th, 2015|WordPress, WordPress Snippets|0 Comments

WordPress Custom Post Types Memory Exhausted Fix

As a web programmer, I'm often asked to fix the problems that others have, but when I see problems appearing on sites I've had a hand in, I'm infinitely more concerned. This is exactly what happened recently, when I custom post type I had provided [...]

2018-02-02T03:09:32+00:00December 1st, 2013|Web Programming, WordPress Snippets|3 Comments

WordPress RSS Widget: Open Links in a New Window

I've recently come across a slight problem with one of my clients whereby they wanted the RSS feed widget to open all incoming links in a new window. And why wouldn't they? Especially if they're external RSS feeds that are being parsed. We could have [...]

2018-02-02T03:09:34+00:00June 4th, 2013|PHP Snippets, WordPress Snippets|1 Comment

Gravity Form Columns – Styling Gravity Forms

Most WordPress developers are familiar with Gravity Forms. It's a contact form plugin that allows you to easily build and publish your forms in just minutes, with the minimum of hassle. No mess, just quick and easy form-building. Select your fields, configure your options and [...]

How to Stop Timthumb Hacks Using .htaccess

How To Block Timthumb Hack Attempts Like many developers I manage a large number of WordPress sites, and in days gone by I'd use TimThumb to handle my images. Sadly, a few years back this became a huge problem since a TimThumb hack surfaced which [...]

Go to Top