Working with Gutenberg and the WordPress REST API

In this article I take the Select2 component that I previously added to my Gutenberg plugin, and make it dynamic by taking advantage of the WordPress REST API. This code borrows heavily from the Secure Blocks for Gutenberg plugin. In this example we will be making the ‘Select Roles’ Inspector use dynamic data from the …

Introducing Secure Blocks for WordPress Gutenberg

Secure your content in the WordPress Gutenberg editor via login or by user role, with Secure Blocks for Gutenberg. Available for download now in the WordPress plugin repository. Using Secure Blocks you can add any Gutenberg block inside a secure block, and have it render only to logged in users, or you can lock it …

Add Select2 as an InspectorControl in WordPress Gutenberg

For a project I was working on I wanted to use Select2 as a Gutenberg InpectorControl to allow me apply settings to a block. Select2 is a super handy replacement for select boxes on your website. In particular it has some great options for selecting multiple items. The finished product, Select2 in the WordPress Gutenberg InspectorControls …

WordPress Syntax Highlighting (Colours) for Code Blocks

You may have noticed that the code examples I use on this site (which runs on WordPress) use a default <code> block, but the code is presented with different colours due to code block syntax highlighting. On my site I use the new (at the time of writing this) WordPress 5 ‘Gutenberg’ editor, which has a …

Custom TinyMCE Editor Formatting in WordPress

Sometimes when writing a block of text using the WordPress editor, you need it to look a certain way, we usually do this by adding styles to peices of text, but we don’t always want our clients to have to open up the text editor and do this manually. In this example we will create …

Changing your WordPress site language (locale) dynamically

There are some fantastic multilingual plugins for WordPress, and WPML is one of my favourites. However for one client project I needed something far more flexible, as this particular client needed to cater for several countries that each spoke several languages. In short the client needed to be able to have a multisite instance that …

Enforce Version Control in WordPress to Boost Security

If you have spent a long time working on your clients website, ensuring everything is in version control (such as git). Then you would be pretty gutted if your client edits a theme file, or adds a new plugin that lives outside of your version controlled workflow. Adding code that lives outside of a tightly controlled workflow means: …

Stop Clickjacking by preventing your WordPress site loading in a Frame

Clickjacking is a potential security risk caused by someone loading your website in a frame on their domain, and hijacking interactions you make with that site. For example if your website requires a user to login, it could log the username and passwords of users targeted by the clickjacking attack. Fortunately preventing clickjacking in WordPress …

Custom conditional statements around your WordPress enqueued stylesheets

You may be aware that you can add conditional statements around your WordPress enqueued CSS styles (such as <!–[if gt IE 7]><link …/><![endif]–>) to load the script for certain versions of Internet Explorer. As handy as this is, it doesn’t cater for all situations. This tutorial will show you how you can expand WordPress to add any type …