Showing all posts (13)

Contact Form 7 upload field with image preview

February 10, 2022

Contact Form 7 allows us to create custom fields that can be used in our form. Let’s create an upload field that will display the image that the user selected before actually uploading it. The technique to do this can be found here: Here’s the form code: Next step: create custom control That’s quite … Read More

PHP: align two arrays by inserting empty spaces

September 4, 2021

Let’s say you have an array $a, representing the current state, and an array $b representing the new state. In order to visualise the difference (or diff for you GIT nerds), we would like to expand both arrays with empty elements so the matching elements align with each other ($a1 and $a2). Note: We assume … Read More

Contact Form 7: hide form after successfully sent, and only display success message.

July 17, 2021

Sometimes you may want to hide your form after a visitor has completed it, and only show the success message. You can achieve this with the following code snippet: You can add this either in your theme’s JS file, or in the form code itself. Notes: If you choose to add this snippet in a … Read More

Gutenberg: Case study: convert group of file blocks to ACF block

August 20, 2020

How to convert a block into another block? Let’s convert this (source block) to this (target block): Before we can do that, we need to define the template for the target block. I’m going to use some very basic Mustache syntax for the template. Should be self-explanatory: Now, all we need to do is create … Read More

Gutenberg – How to update blocks and block-templates in bulk

August 8, 2020

At the time of writing, there is still no documented way to update blocks. So here is how I would update all my blocks: Loop trough all posts. Find patterns matching:<!– your-block –>*<!– /your-block –> Optional: convert the block to PHP Array with parse_blocks() Replace according to your new block Save post with the updated … Read More

Create your own wp-env npm package

July 30, 2020

wp-env is a super nice tool to kickstart plugin and/or theme development. It is zero-config, which makes it very usefult for people who don’t like to mess around with Dockerfiles, manually downloading WP, basic configuration, setting up a DB, … So that’s almost everyone, right? Well.. I don’t think so. While I do believe that … Read More

Contact Form 7 toggle buttons

June 14, 2020

You don’t need any fancy plugins to turn your checkboxes or radiobuttons into actual buttons. Just good old CF7 with some basic CSS will do. Simply create your form like this: It’s very important to include: use_label_element and class:togglebuttons. Then add these CSS style rules to your theme (or via the Customizer): Extra: tabs Did … Read More

Gutenberg: how to insert a reusable block in the editor with JavaScript

May 23, 2020

Accessing core blocks and custom made blocks, is pretty straight forward. For example, if you want to get the paragraph block, you could do so with: And if you want to insert a paragraph, you can easily do so with: There’s even a convenient way to get ALL registered blocks as an array with However, … Read More

Gutenberg: how to force sidebar to be always open on post edit screen

May 18, 2020

Add this to your functions.php … Read More

Gutenberg: custom validation / how to prevent post from being saved

May 17, 2020

This script will disable the Publish/Update button: To make the post publishable again, you can do: Very nice. But how is this useful? Here are a couple of use cases. Force users to enter a post title. Let’s say you want to force your users to at least enter a title before they can save … Read More

Gutenberg: Prevent specific block from being removable

May 14, 2020

Ideally, we should use template_lock as much as we possibly can. But with the problems it introduces currently, and because there might be special use cases that template locking cannot handle, I wanted to explore a way to prevent a specific block from being deletable. If you’re comming from a jQuery background (which is likely … Read More

Gutenberg: Problems with template_lock

May 11, 2020

In my previous post, I described a way for developers to create a custom user interface for a specific post type. This approach relies heavily on using template_lock=’all’ in combination with templateLock={false} on some of the child blocks. Problem 1: there’s a warning Each published Book that you try to edit, will show this warning … Read More

Gutenberg: creating an advanced custom admin user interface for your post types with the block editor using template lock.

May 9, 2020

As a freelance developer, I want my clients to have an easy to use interface when creating posts. Before WP 5.0 (and before Gutenberg) I used Advanced Custom Fields a lot for this purpose. An example interface for a Book post, could look something like this: As you can see, I want to add the … Read More