Skip to content

Instantly share code, notes, and snippets.

View wpmark's full-sized avatar

Mark Wilkinson wpmark

View GitHub Profile
wpmark / render-post-terms-block-output.php
Created March 17, 2023 10:08
Modify the post terms block output in WordPress
* Changes the links on post terms block for job listing category terms.
* @param string $block_content The block content.
* @param array $block The full block, including name and attributes.
* @param WP_Block $instance The block instance.
* @return string $block_content The block content.
wpmark /
Last active June 1, 2023 20:32
Escaping output with only specific allowed HTML elements.

Escaping output with only specific allowed HTML elements

Sometimes when developing for WordPress, you will want to echo something. As all good developers know, any such content must be escaped. This makes sure that nothing nasty can be echoed and keeps you code more secure.

WordPress comes with a number of escaping functions, however sometimes they don't quite do as you want. Take this example.

wpmark / php-block-styles.php
Last active December 19, 2022 08:51
Register WordPress block styles with PHP
* Register some default block editor styles for this block.
function hd_testimonials_register_testimonials_block_styles() {
// add the small image style.
'core/heading', // name of your block
wpmark / register-facets-in-php.php
Last active March 14, 2023 11:22
Register Facets with the excellent FacetWP plugin via PHP
* Registers the Facets with FacetWP.
* @param array $facets The current array of registered facets.
* @return array $facets The modified array of registered facets.
function hd_utility_add_job_facets( $facets ) {
// add the job industry facet.
wpmark / placeholder-image-id-setting.php
Created March 24, 2022 15:56
Add a placeholder image ID setting in WordPress, under Settings > Media
* Registers any additional settings required for the plugin.
* Registers the setting for the placeholder attachment ID.
function hd_utility_register_image_placeholder_id_setting() {
wpmark / wp-email-tweaks.php
Created October 12, 2021 17:55
Easily customise the name and email address of WordPress emails
* Used to filter email from 'address'
function hd_email_send_wp_mail_address( $input ) {
// return a new from email address.
return '';
wpmark / alignment-options.js
Last active January 4, 2023 07:50
Add alignment options for WordPress core blocks.
// set alignment options for cover, video, and paragraph blocks.
function( settings, name ) {
if ( name === 'core/cover' || name === 'core/video' || name === 'core/paragraph' || name === 'core/list' ) {
return lodash.assign( {}, settings, {
supports: lodash.assign( {}, settings.supports, {
// allow support for full and wide alignment.
align: ['full', 'wide'],
wpmark /
Last active February 1, 2023 11:06
An example of caching data using a WordPress transient

Caching WordPress data using Transients - Example

In this simple example we create a function for obtaining data from an external source and caching it for 24 hours. You can use the function hd_get_external_data() to get the data and work with it in your site.

If you want to force a refresh of the cache, you can pass a value of true into the function.

You can place the code into your themes functions.php file or better still in a plugin. If you are placing it in a plugin, remember to use function_exists() when using this. This ensures that the code will fail correctly if the plugin is not active.

wpmark / post-type-support.php
Created October 8, 2021 13:26
Add post type support for the post excerpt
* Add support for the excerpt on pages.
function hd_add_custom_post_type_excerpt_support() {
// add post type support for pages.
add_post_type_support( 'page', 'excerpt' );
// add post type support for case studies.
wpmark / hd-just-in-time-css.php
Created August 13, 2021 09:13
A plugin to provide Just in Time CSS for WordPress blocks
Plugin Name: Just in Time CSS
Plugin URI:
Description: A plugin from Highrise Digital to provide just in time CSS functionality.
Version: 1.0
License: GPL-2.0+
Author: Highrise Digital Ltd
Author URI:
Text domain: hd-just-in-time-css