Skip to content

Instantly share code, notes, and snippets.

/**
* Add Async & Defer to certain scripts.
*
* @param string $tag Script Tags to display.
* @param string $handle Name of file specified above.
*/
function add_async_defer_attribute( $tag, $handle ) {
$scripts = array( 'script-handle' );
foreach ( $scripts as $script ) {
/**
* Add Security Key and appropiate tags Enqueued Scripts & Styles.
*
* @param string $tag Script Tags to display.
* @param string $handle Name of file specified above.
*/
function script_security_checks( $tag, $handle ) {
$scripts = array( 'script_handle' );
@addzycullen
addzycullen / WordPress Debug Log | Enable Log
Last active March 10, 2023 12:34
Enable the WordPress Debug log, and hide errors from displaying on site. To be placed in wp_config file below DB prefix
define( 'WP_DEBUG', true );
if ( WP_DEBUG ) {
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
define( 'SCRIPT_DEBUG', true );
define( 'SAVEQUERIES', true );
}
@addzycullen
addzycullen / WordPress Debug Log | Write to Log
Created June 10, 2019 13:37
This fn allows you write to the WordPress debug log if you have it enabled in the wp_config file.
/**
* Write to Debug Log
*
* Add to your functions.php file for use in a theme.
* Remember to remove from live environment.
*
* @param object $log
* @return void
*/
if (!function_exists('write_log')) {
@addzycullen
addzycullen / PHP | Format UK telephone numbers for href
Last active June 10, 2019 13:51
Telephone Number Format for href - Adapted from another source, unfortunately I don't recall where, let me know if you have seen this anywhere so I can credit.
/*
$original = '+44 (0)1234 567 890';
$original = '0044 01234 567 890';
$original = '01234 567 890';
$original = '44 1234 567 890';
Result should always be: +441234567890
*/
// Strip out all characters apart from numbers