Skip to content

Instantly share code, notes, and snippets.

Avatar
✍️
Writing

Brian Jackson brianleejackson

✍️
Writing
View GitHub Profile
View ninja-forms-perfmatters-delay-js-exclusions.php
add_filter('perfmatters_delay_js_exclusions', function($exclusions) {
if(is_page(275)) {
$exclusions[] = 'underscore.min.js';
$exclusions[] = 'backbone.min.js';
$exclusions[] = 'front-end-deps.js';
$exclusions[] = 'front-end.js';
$exclusions[] = 'nf-';
$exclusions[] = 'jquery.min.js';
$exclusions[] = 'nfForms';
}
@brianleejackson
brianleejackson / mobile-cache-buckets.php
Last active Jul 31, 2022
Testing mobile cache buckets. This snippet echos out text only on desktop in the footer. If you see it on mobile, it means your mobile cache bucket isn't configure properly.
View mobile-cache-buckets.php
add_action('wp_footer', function() {
if(!wp_is_mobile()) {
echo 'hello world';
}
});
@brianleejackson
brianleejackson / fastclick-delay-js-workaround.js
Last active Apr 11, 2022
FastClick Delay JS workaround for iOS double-click bug. As used here: https://perfmatters.io/docs/delay-javascript/
View fastclick-delay-js-workaround.js
<script src="https://cdnjs.cloudflare.com/ajax/libs/fastclick/0.6.0/fastclick.min.js" integrity="sha512-oljyd1wg75alHReTpDvNIQ4Yj1wZwGxxZhJhId3vr2dKY+26/r/wmMrImwDgin03+7wxyhX+adOQB/2BTvO5tQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
if ('addEventListener' in document) {
document.addEventListener('DOMContentLoaded', function() {
FastClick.attach(document.body);
}, false);
}
</script>
View author-bio-box.css
/*author bio box*/
a.gb-button {
border-bottom: none !important;
}
.author-box a {
border-bottom: 2px solid rgba(35, 117, 214, 0.4);
}
.author-description {
margin-bottom: 5px;
}
View remove-query-strings-wordpress.php
/* Remove Query Strings
/***********************************************************************/
add_action('init', 'remove_query_strings');
function remove_query_strings() {
if(!is_admin()) {
add_filter('script_loader_src', 'remove_query_strings_split', 15);
add_filter('style_loader_src', 'remove_query_strings_split', 15);
}
}
function remove_query_strings_split($src) {
@brianleejackson
brianleejackson / novashare-news-refresh-rate-12-hours.php
Created Jan 6, 2021
Novashare news site refresh rate (12 hours)
View novashare-news-refresh-rate-12-hours.php
function novashare_custom_refresh_rates($rates) {
return array(
'max' => 5184000, //60 days in seconds
'sets' => array(
array(
'modified' => 604800, //7 days in seconds
'rate' => 43200 //12 hours in seconds
),
array(
'modified' => 2419200, //28 days in seconds
@brianleejackson
brianleejackson / novashare-news-refresh-rate-24-hours.php
Last active Jan 6, 2021
Novashare news site refresh rate (24 hours)
View novashare-news-refresh-rate-24-hours.php
function novashare_custom_refresh_rates($rates) {
return array(
'max' => 5184000, //60 days in seconds
'sets' => array(
array(
'modified' => 604800, //7 days in seconds
'rate' => 86400 //24 hours in seconds
),
array(
'modified' => 2419200, //28 days in seconds
View generatepress-font-display-swap.php
add_filter( 'generate_google_font_display', function() {
return 'swap';
} );
View generateblocks-pricing-table.json
{
"__file": "wp_block",
"title": "Pricing table",
"content": "<!-- wp:generateblocks/container {\"uniqueId\":\"d1bb3ef9\",\"paddingTop\":\"0\",\"paddingRight\":\"20\",\"paddingLeft\":\"0\"} -->\n<div class=\"gb-container gb-container-d1bb3ef9\"><div class=\"gb-inside-container\"><!-- wp:generateblocks/grid {\"uniqueId\":\"28a352a0\",\"columns\":3,\"horizontalGap\":40} -->\n<div class=\"gb-grid-wrapper gb-grid-wrapper-28a352a0\"><!-- wp:generateblocks/container {\"uniqueId\":\"614c94ee\",\"isGrid\":true,\"gridId\":\"3ab20ff8\",\"width\":33.33,\"paddingTop\":\"0\",\"paddingRight\":\"0\",\"paddingBottom\":\"0\",\"paddingLeft\":\"0\",\"marginTop\":\"90\",\"marginTopMobile\":\"5\",\"gradient\":true,\"gradientDirection\":360,\"gradientColorOne\":\"#f3f3f3\",\"gradientColorTwo\":\"#f3f3f3\",\"gradientColorTwoOpacity\":0.5} -->\n<div class=\"gb-grid-column gb-grid-column-614c94ee\"><div class=\"gb-container gb-container-614c94ee\"><div class=\"gb-inside-container\"><!-- wp:generateblocks/headline {\"uniqueId\":
@brianleejackson
brianleejackson / enqueue-preload-font.php
Created Sep 23, 2020
Enqueue and preload a font in WordPress
View enqueue-preload-font.php
function enqueue_font_preload() {
wp_enqueue_style('example-font-handle', 'https://domain.com/wp-content/font-file.woff2', array(), null);
}
add_action('wp_enqueue_scripts', 'enqueue_font_preload');
function style_loader_tag_filter_preload($html, $handle) {
if($handle === 'example-font-handle') {
$new_html = str_replace("text/css", "font/woff2", $html);
return str_replace("rel='stylesheet'", "rel='preload' as='font' crossorigin='anonymous'", $new_html);
}
return $html;