Skip to content

Instantly share code, notes, and snippets.

View brianleejackson's full-sized avatar
✍️
Writing

Brian Jackson brianleejackson

✍️
Writing
View GitHub Profile
@brianleejackson
brianleejackson / disable-wordpress-fetch-priority.php
Created December 8, 2023 03:58
Disable WordPress core fetch priority
function disable_fetchpriority_high( $loading_attrs ) {
unset( $loading_attrs['fetchpriority'] );
return $loading_attrs;
}
add_filter(
'wp_get_loading_optimization_attributes',
'disable_fetchpriority_high'
);
/* 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 / divi-cls-fix.js
Created November 20, 2023 02:54
Fix Divi CLS
<script type="text/javascript">
var elm=document.getElementsByTagName("html")[0];
elm.style.display="none";
document.addEventListener("DOMContentLoaded",function(event) {elm.style.display="block"; });
</script>
<?php
add_action( 'shutdown', function() {
// If the event is scheduled, don't run anything.
if ( wp_next_scheduled( 'prefix_remove_license_activation_logs' ) ) {
return;
}
if ( ! function_exists( 'edd_has_upgrade_completed' ) ) {
@brianleejackson
brianleejackson / obsidian-custom-css.css
Last active July 21, 2023 05:06
Obsidian custom CSS
/* preview-mode paragraphs */
p{
padding-top: 6px;
padding-bottom: 6px;
line-height: 1.6;
}
/* preview-mode lists */
li{
padding-top: 6px;
@brianleejackson
brianleejackson / remove-slug-cpt.php
Last active June 1, 2023 11:41
Remove base slug from custom post type URL. Source: https://woorkup.com/wordpress-custom-post-type/
function na_remove_slug( $post_link, $post, $leavename ) {
if ( 'artist' != $post->post_type || 'publish' != $post->post_status ) {
return $post_link;
}
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
return $post_link;
}
@brianleejackson
brianleejackson / fastclick-mobile-only.js
Created March 1, 2023 22:32
Only load FastClick on mobile devices (no tablets or desktop)
<script>
if (window.innerwidth < 900) {
document.write('<script type="text/javascript" src="https://domain.com/wp-content/plugins/perfmatters/vendor/fastclick/fastclick.min.js"><\/script>');
}
</script>
<script>
if(window.innerWidth < 900) {
if('addEventListener' in document) {
document.addEventListener('DOMContentLoaded', function() {
@brianleejackson
brianleejackson / woorkup.css
Last active February 3, 2023 02:52
woorkup custom CSS used with GeneratePress theme. Source: https://woorkup.com/generatepress-review/
html {-webkit-font-smoothing: auto;}
/*fonts*/
strong {color:#202020;}
/*no margin mobile*/
@media screen and (max-width: 768px) {
.no-margin-mobile {margin-bottom:0px;}}
/*links*/
#block-2 a {text-decoration:none;}
#block-2 {border: 1px solid rgba(0,0,0,.05);
box-shadow: 0 0 27px 0 rgb(214 231 233 / 52%);
@brianleejackson
brianleejackson / lazy-render.css
Last active January 24, 2023 00:01
Add content-visibility to WordPress element (lazy render)
.nameofdiv {
content-visibility: auto;
contain-intrinsic-size: 0 1000px;
}
/* References:
https://web.dev/content-visibility/
https://segmentfault.com/a/1190000041980427/en
https://clubmate.fi/content-visibility-auto
https://dev.to/dailydevtips1/i-made-my-website-28ms-faster-with-content-visibility-466e
@brianleejackson
brianleejackson / gp-updated-date.php
Last active January 9, 2023 14:05
Display the date a post was updated in the GeneratePress 3.0 theme as seen on https://woorkup.com
add_filter( 'generate_post_date_output', function( $output, $time_string ) {
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on %2$s</time>';
if ( get_the_date() !== get_the_modified_date() ) {
$time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">Updated on %4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),