In the WordPress block editor (a.k.a. Gutenberg) the “Featured Image” is rendered at the WordPress ‘large’ image size by default. By adding a WordPress JavaScript filter to the ‘editor.PostFeaturedImage.imageSize’ hook, we can change this default rendering.
WordPress Filter
WordPress Filter Early Return Pattern
A common programming pattern when using WordPress filters is the early return pattern (also know as the “short-circuit” pattern). This pattern is useful when you want to allow a filter to override a value that is “expensive” to calculate.
WordPress Hooks and PHP Namespaces
While PHP namespaces allow you to refer to a function in file without using the fully qualified name, there is a catch when adding a WordPress hook or filter. The PHP __NAMESPACE__ magic constant can be helpful in this situation.
Add WordPress Posts Column
Code to add a custom column to the WP Admin Posts listing page.
Add Gutenberg JavaScript Filter
WordPress PHP filters allow you make a value modifiable from outside of your code. With the WordPress Block Editor (a.k.a. Gutenberg), you can now do the same thing in JavaScript.
How to Add a Twitter Hashtag with Scriptless Social Sharing
When using Scriptless Social Sharing, you may want to add a site wide hashtag to all of your tweets. This is the code you can use to do that.
Override WordPress Publish Date on Creation
When creating new posts for a video demonstration, I wanted to display a consistent date. While my first thought was to reset my system clock, this snippet overrides the date when the post is first created, which worked for me.
Remove target _blank from the Scriptless Social Sharing Email button
I like to use the Scriptless Social Sharing WordPress plugin to add Share buttons to my blog posts. Recently I had a client notice that because the Email Share button has target=”_blank” in the HTML markup, it opens a new tab when clicked. This is great behavior if you’re using web based email (e.g. Gmail), however if you’re using an email application on your computer, you end up with a blank tab. This code removes target blank from the email share link.
Featured Image Label for WordPress
I often find it helpful to add a label to the Featured Image area in the WordPress admin. By guiding clients to upload the appropriate sized image, it lets me avoid them being surprised by WordPress cropping their image in an unexpected way.
UTM parameters with Scriptless Social Sharing
When it comes to adding social sharing buttons (e.g. “Share on Facebook”), I’m a big fan of Scriptless Social Sharing by Robin Cornett. The one thing I like to do when using it is add UTM parameters to the links that are shared. Here is the snippet I use to add UTM parameters to my URLs that are being shared.