Skip to content

Instantly share code, notes, and snippets.

View wpmark's full-sized avatar

Mark Wilkinson wpmark

View GitHub Profile
@wpmark
wpmark / post-type-support.php
Created October 8, 2021 13:26
Add post type support for the post excerpt
<?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 / readme.md
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
wpmark / wp-email-tweaks.php
Created October 12, 2021 17:55
Easily customise the name and email address of WordPress emails
<?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 January 4, 2023 07:50
Add alignment options for WordPress core blocks.
// 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 / php-block-styles.php
Last active December 19, 2022 08:51
Register WordPress block styles with 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 / extensible-changes.php
Created October 6, 2020 13:35
HD Extensible Social Profiles Widget
<?php
/**
* Edit the social profiles available.
*
* @param array $profiles The current array of registered social profiles.
* @return array The modified array of registered social profiles.
*/
function hd_test_edit_social_profile( $profiles ) {
// if we have a linkedin profile.
@wpmark
wpmark / gist:9d5d2395cb01a2de0179
Created October 8, 2014 11:06
Check If WordPress Post is Older than X Days
<?php
/*******************************
* this will work in the loop
*******************************/
/* check if the posts publish date is older than 60 days */
if( strtotime( $post->post_date ) < strtotime('-60 days') ) {
/* post is older than 60 days - do something with it!! */
@wpmark
wpmark / placeholder-image-id-setting.php
Created March 24, 2022 15:56
Add a placeholder image ID setting in WordPress, under Settings > Media
<?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 / hd-just-in-time-css.php
Created August 13, 2021 09:13
A plugin to provide Just in Time CSS for WordPress blocks
<?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 / using-media-handle-sideload.php
Created July 10, 2015 10:32
Using Media Handle Sideload
<?php
/* set the url of the file to sideload - probably be from $_POST or something */
$url = 'http://domain.com/image.jpg';
/**
* donwload the url into wordpress
* saved temporarly for now
*/
$tmp = download_url( $url );