Skip to content

Instantly share code, notes, and snippets.

View benpearson's full-sized avatar

Ben Pearson benpearson

  • Melbourne, Australia
View GitHub Profile
@benpearson
benpearson / advanced-custom-fields.php
Created January 9, 2025 07:14
WordPress: Reverse ACF query example
/**
* Example: Reverse ACF query
*/
function dt_get_related_sport_icon_positive($post)
{
$related_sport_icon_positive = null;
$sports_term_objects = get_the_terms($post, 'sport_category');
@benpearson
benpearson / wp-head.php
Created January 9, 2025 07:07
Legacy clean up of wp_head()
<?php
/**
* Clean up wp_head()
*/
remove_action('wp_head', 'feed_links_extra', 3); // Display the links to the extra feeds such as category feeds
remove_action('wp_head', 'feed_links', 2); // Display the links to the general feeds: Post and Comment Feed
remove_action('wp_head', 'rsd_link'); // Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action('wp_head', 'wlwmanifest_link'); // Display the link to the Windows Live Writer manifest file.
@benpearson
benpearson / meta-boxes.php
Created January 9, 2025 04:33
WordPress: Moving third party meta boxes (rankmath, aioseo, wpseo)
<?php
/**
* Meta boxes
*/
// Move Rank Math meta box below ACF meta boxes
function dt_rankmath_post_metabox_priority()
{
return 'low';
@benpearson
benpearson / menu-filters.php
Created January 9, 2025 04:31
WordPress: Examples of menu filters (including nav menu widgets)
<?php
/**
* Menu: Filters
*/
/**
* WP_Nav_Menu_Widget: Edit params to add wrapping HTML
*/
@benpearson
benpearson / images.php
Created January 9, 2025 04:29
Wordpress: Increase the maximum image width to be included in a ‘srcset’ attribute
// Increase the maximum image width to be included in a ‘srcset’ attribute (default is 1600px)
function dt_max_srcset_image_width()
{
return 2000;
}
// add_filter( 'max_srcset_image_width', 'dt_max_srcset_image_width', 10 , 2 );
@benpearson
benpearson / images.php
Created January 9, 2025 04:28
Wordpress: Filter the image sizes automatically generated when uploading an image
// Filter the image sizes automatically generated when uploading an image.
function dt_remove_default_image_sizes($sizes)
{
unset($sizes['thumbnail']);
// unset( $sizes['medium']); // medium image size is used by WP Media Library for thumbnails
unset($sizes['medium_large']);
unset($sizes['large']);
return $sizes;
}
// add_filter( 'intermediate_image_sizes_advanced', 'dt_remove_default_image_sizes' );
@benpearson
benpearson / acf-color-picker-palette.js
Last active April 1, 2025 01:05
WordPress: Enqueue filter for ACF colour picker
// ACF colour picker palette
acf.add_filter('color_picker_args', function( args, $field ){
args.palettes = ['#000000', '#FFFFFF', '#FC4D00', '#6750AA', '#F2E9DB', '#DCD3E7']
return args;
});
@benpearson
benpearson / blocks-allowed.php
Created January 9, 2025 04:01
WordPress: Filter what blocks are allowed where
<?php
/**
* Allowed blocks
*
* What blocks are allowed where
*/
/**
* Allowed core and ACF blocks
@benpearson
benpearson / admin-email.php
Last active January 9, 2025 06:58
WordPress: Disable new user registration email
<?php
/**
* Admin emails
*/
function dt_disable_new_user_registation_email() {
remove_action('register_new_user', 'wp_send_new_user_notifications');
remove_action('edit_user_created_user', 'wp_send_new_user_notifications', 10, 2);
@benpearson
benpearson / page-sitemap.php
Created January 8, 2025 23:29
Wordpress: Sitemap page template
<?php
/**
* Template Name: Sitemap
*/
?>
<?php get_header(); ?>
<div class="site-map">