Code Snippets

Recent Code Snippets

Allow JSON Uploads to WordPress Media Library

Source: https://koop.sh/software/allow-json-uploads-to-wordpress-media-library/

October 4, 2022

WooCommerce – Custom Order Status

PHPadd_action( 'init', function() { register_post_status( 'wc-backorder', [ 'label' => 'On backorder', 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true,…

September 26, 2022

Breadcrumbs

Start with Yoast SEO Breadcrumbs, but fallback to Jetpack. WooCommerce: Rename Home:

September 13, 2022

Custom Login Page

Change URL for Login Logo: Hide Powered by WordPress Title:

September 13, 2022

Jetpack: remove External Media from the block editor

PHP/** * Remove Jetpack's External Media feature. */ add_action( 'enqueue_block_editor_assets', function () { $disable_external_media = <<<JS document.addEventListener( 'DOMContentLoaded', function() {…

September 13, 2022

Jetpack Related Posts

Set a default image: Exclude posts without images: Sources:

September 13, 2022

Jetpack: Add UTM Tracking to Sharing Buttons

PHP/** * Overwrite the links used in Jetpack's Sharing module. * * @see https://wordpress.org/support/topic/how-to-use-utm-codes-with-jetpack-sharing * * @param string $url *…

September 13, 2022

Jetpack Subscriptions

PHP/** * Redirect all successful subscription submissions to a 'thank-you' page. */ function hlabs_custom_sub_redirect_page( $result ) { if ( 'success'…

September 13, 2022

Check WordPress Requirements

PHP

September 13, 2022

Date & Time Snippets for WordPress

PHP$time_now = new DateTimeImmutable( 'now', wp_timezone() ); $time_tonight = new DateTimeImmutable( 'today 24:00', wp_timezone() ); $seconds_remaining = $time_tonight->getTimestamp() - $time_now->getTimestamp();

September 13, 2022