Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Wilkinson wpmark

View GitHub Profile
@wpmark
wpmark / php-block-styles.php
Last active May 11, 2022
Register WordPress block styles with PHP
View php-block-styles.php
<?php
/**
* Register some default block editor styles for this block.
*/
function hd_testimonials_register_testimonials_block_styles() {
// add the small image style.
register_block_style(
'core/heading', // name of your block
array(
@wpmark
wpmark / register-facets-in-php.php
Created Mar 24, 2022
Register Facets with the excellent FacetWP plugin via PHP
View register-facets-in-php.php
<?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
wpmark / placeholder-image-id-setting.php
Created Mar 24, 2022
Add a placeholder image ID setting in WordPress, under Settings > Media
View placeholder-image-id-setting.php
<?php
/**
* 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
wpmark / wp-email-tweaks.php
Created Oct 12, 2021
Easily customise the name and email address of WordPress emails
View wp-email-tweaks.php
<?php
/**
* Used to filter email from 'address'
*/
function hd_email_send_wp_mail_address( $input ) {
// return a new from email address.
return 'no-reply@highrise.digital';
}
@wpmark
wpmark / alignment-options.js
Last active Oct 29, 2022
Add alignment options for WordPress core blocks.
View alignment-options.js
// set alignment options for cover, video, and paragraph blocks.
wp.hooks.addFilter(
'blocks.registerBlockType',
'hd-theme/hd-theme',
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
wpmark / readme.md
Last active Jun 13, 2022
An example of caching data using a WordPress transient
View readme.md

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
wpmark / post-type-support.php
Created Oct 8, 2021
Add post type support for the post excerpt
View post-type-support.php
<?php
/**
* 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
wpmark / hd-just-in-time-css.php
Created Aug 13, 2021
A plugin to provide Just in Time CSS for WordPress blocks
View hd-just-in-time-css.php
<?php
/*
Plugin Name: Just in Time CSS
Plugin URI: https://highrise.digital/
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: https://highrise.digital/
Text domain: hd-just-in-time-css
@wpmark
wpmark / hd-user-categories.php
Created Jun 11, 2021
A WordPress plugin that adds categories to users. It allows you to assign categories to users which you could then use elsewhere in your site.
View hd-user-categories.php
<?php
/*
Plugin Name: User Categories
Plugin URI: https://highrise.digital/
Description: Adds categories to users. It allows you to assign categories to users which you could then use elsewhere in your site.
Version: 1.0
License: GPL-2.0+
Author: Highrise Digital Ltd
Author URI: https://highrise.digital/
Text domain: hd-user-categories
@wpmark
wpmark / highrise-auto-updater.php
Created Mar 31, 2021
Allow WordPress to auto update eveything.
View highrise-auto-updater.php
<?php
/*
Plugin Name: Highrise Digital Auto Updater
Plugin URI: https://highrise.digital/
Description: A plugin to set WordPress to auto update everything.
Version: 1.0
License: GPL-2.0+
Author: Highrise Digital
Author URI: https://highrise.digital/
Text domain: highrise-auto-updater