Skip to content

Instantly share code, notes, and snippets.

View warwickandersonza's full-sized avatar
🦕

Warwick Anderson warwickandersonza

🦕
  • Cape Town, South Africa
View GitHub Profile
@warwickandersonza
warwickandersonza / debug.php
Last active April 22, 2024 18:18
Asynchronous WordPress debugging functions
<?php
define( 'WAR_LOG_FILE', sprintf( '%s%sdebug.html', __DIR__, DIRECTORY_SEPARATOR ) );
define( 'WAR_LOG_URL', sprintf( 'https://%s/debug.php', $_SERVER['HTTP_HOST'] ?? '' ) );
/**
* @param mixed $arg
*
* @return mixed
*/
@warwickandersonza
warwickandersonza / elementor-preload-background-images.php
Last active June 12, 2024 19:18
Preload Elementor background images
<?php
/**
* Preload Elementor background images if they are among the first elements on a page.
*
* @return void
*/
function sitecare_preload_elementor_background_images(): void {
if ( ! did_action( 'elementor/loaded' ) ) {
@warwickandersonza
warwickandersonza / elementor-image-widget-loading.php
Last active June 12, 2024 19:17
Elementor image widget loading strategy control
<?php
/**
* Add a control to the Elementor Image Widget to explicitly adjust the loading strategy.
*
* @param \Elementor\Widget_Image $element
*
* @return void
*/
function sitecare_elementor_image_widget_loading_control( \Elementor\Widget_Image $element ): void {
@warwickandersonza
warwickandersonza / jquery-in-footer.php
Last active April 22, 2024 18:04
Move WordPress jQuery to the footer
@warwickandersonza
warwickandersonza / cli-cache.sh
Created April 22, 2024 18:27
Clearing cache with WP-CLI
# Run this at the beginning of the sessions in case the host removed packages after disconnecting
wp package install wp-media/wp-rocket-cli:trunk
# On WPEngine, this will clear all caches, including Cloudflare
wp rocket clean --confirm && wp cache flush
@warwickandersonza
warwickandersonza / facetwp-optimize-loading-strategy.php
Last active June 12, 2024 19:18
Optimize FacetWP preloaded image strategy
/**
* Applies eager loading to the first three (3) posts in the "recipe_list" FacetWP listing.
*
* @param array $output
* @param array $params
*
* @return array
*/
function sitecare_facetwp_image_loading_strategy( array $output, array $params ): array {