Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Wilkinson wpmark

View GitHub Profile
@wpmark
wpmark / render-post-terms-block-output.php
Created March 17, 2023 10:08
Modify the post terms block output in WordPress
View render-post-terms-block-output.php
<?php
/**
* 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
wpmark / register-facets-in-php.php
Last active March 14, 2023 11:22
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.
View show-admin-display-hooks.php
<?php
/*
Plugin Name: Show Admin Display Hooks
Plugin URI: http://github.com/wpmark/show-admin-display-hooks
Description: Make visible all the hooks in the WordPress admin area that are available for outputting content on different admin screens.
Version: 0.1
Author: Mark Wilkinson
Author URI: http://markwilkinson.me
License: GPLv2 or later
*/
@wpmark
wpmark / wp-dashboard-tabs.php
Created March 18, 2015 19:22
WordPress Dashboard Tabs
View wp-dashboard-tabs.php
<?php
/***************************************************************
* Function wpbasis_dashboard_content()
* Pulls in the new dashboard page content from plugin file
***************************************************************/
function wpbasis_dashboard() {
/* check for a dashboard content file in the theme folder */
if( file_exists( STYLESHEETPATH . '/wpbasis/dashboard.php' ) ) {
/* load the dashboard content file from the theme folder */
get_template_part( 'wpbasis/dashboard', 'content' );
@wpmark
wpmark / wp-query-orderby-muliple-meta-keys.php
Created November 18, 2015 12:48
WP_Query Ordered By Multiple Meta Keys
View wp-query-orderby-muliple-meta-keys.php
<?php
/* build a new wp_query */
$classes = new WP_Query(
array(
'post_type' => 'wpmark_class_time', // post type to query
'posts_per_page' => -1, // get all the posts not limited
'meta_query' => array(
'relation' => 'AND',
'day' => array( // give the first meta key array an array key
'key' => '_wpmark_day',
@wpmark
wpmark / wp-dev-env-body-class.php
Created October 15, 2020 12:13
Output a body class based on the WP development environment
View wp-dev-env-body-class.php
<?php
/**
* Adds a body class for the environment.
*
* @param array $classes The current array of body classes.
* @return array The new array of body classes.
*/
function hd_env_body_class( $classes ) {
// if WP environment function exists.
@wpmark
wpmark / post-type-support.php
Created October 8, 2021 13:26
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 / readme.md
Last active February 1, 2023 11:06
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 / wp-email-tweaks.php
Created October 12, 2021 17:55
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 / hd-user-categories.php
Created June 11, 2021 11:05
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