Showing all posts (13)

Javascript: one-pager navigation with IntersectionObserver

July 28, 2023

See the Pen One-pager navigation with intersectionObserver by Jules Colle (@pwkip) on CodePen. Turn it into a reusable function, so we can also apply it on vertical secondary navigation. See the Pen One-pager navigation with intersectionObserver by Jules Colle (@pwkip) on CodePen. … Read More

CSS: change a transparent PNG to any color you want.

July 9, 2023

TL;DR The trick is to drop a shadow on the PNG image, give the shadow the desired color and make sure the shadow is far away from the image. Finally, move the image out of view, just far enough for the shadow to move into view. CSS: HTML: With all the latest and greatest CSS … Read More

Gutenberg / Block editor: Dynamically populate SelectControl, RadioControl or CheckboxControl options

November 25, 2022

If you have some experience with Gutenberg development, It’s easy enough to create a simple control that lets a user select one or more options, like this: In this example we save the selected option to and load it from post meta. We use withSelect and withDispatch for this: and we also need to register … Read More

HTML/PHP: Drag and drop upload files

October 20, 2022

Note: this article shows how you can create a drag-and-drop upload field to upload multiple files with some basic HTML, CSS and JavaScript.Using Contact Form 7? Check out this article instead: How to upload multiple files with drag and drop with Contact Form 7. In most modern browsers, you can drag files to the upload … Read More

Contact form 7 dynamic values

October 13, 2022

A little known fact about Contact Form 7 is that you can dynamically set the values of your form input fields. Every Contact Form 7 input field supports the data-attribute. An advanced example on how to use this attribute can be found here: Dynamically populate a Contact Form 7 dropdown list (or any other input … Read More

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