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 / line-breaks-fluent-forms.php
Created December 28, 2022 17:59
Remove additional line breaks in Fluent Forms WordPress plugin
add_filter('fluentform_response_render_textarea', function ($value, $field, $formId, $isHtml) {
if (false != strpos($value, '<br />')) {
$value = str_replace('<br />', '', $value);
}
return '<span style="white-space: pre-line">' . $value . '</span>';
}, 15, 4);
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 July 31, 2022 21:09
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.
add_action('wp_footer', function() {
if(!wp_is_mobile()) {
echo 'hello world';
}
});
@brianleejackson
brianleejackson / gp-read-more.php
Last active July 13, 2022 21:34
GeneratePress read more link on blog post archive, as seen on https://woorkup.com
add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' );
function tu_excerpt_metabox_more( $excerpt ) {
$output = $excerpt;
$settings = wp_parse_args(
get_option( 'generate_blog_settings', array() ),
generate_blog_get_defaults()
);
if ( has_excerpt() ) {
$output = sprintf('%1$s <br /><a class="read-more" href="%2$s">%3$s →</a>',
@brianleejackson
brianleejackson / fastclick-delay-js-workaround.js
Last active April 11, 2022 02:12
FastClick Delay JS workaround for iOS double-click bug. As used here: https://perfmatters.io/docs/delay-javascript/
<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>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
@brianleejackson
brianleejackson / remove-slug-cpt-alternate.php
Last active November 14, 2021 10:52
Alternative way to remove the base slug from custom post type URL. Source: https://woorkup.com/wordpress-custom-post-type/
function bis_remove_cpt_slug($args, $post_type) {
if(in_array($post_type, array('artist'))) {
$args['rewrite'] = array('slug' => '/');
}
return $args;
}
add_filter('register_post_type_args', 'bis_remove_cpt_slug', 10, 2);
@brianleejackson
brianleejackson / exclude-logo-lazy-load-generatepress.php
Last active June 29, 2021 18:59
Exclude logo (desktop and mobile) from lazy load in GeneratePress theme with Perfmatters plugin. Source: https://perfmatters.io/docs/lazy-load-wordpress/ *Update* This is no longer needed as you can add class exclusions in Perfmatters.
//add no-lazy class to primary logo
function wpd_generate_logo_output($output, $logo_url, $html_attr) {
//add our no-lazy class
$html_attr = str_replace('class="', 'class="no-lazy ', $html_attr);
//logo output
printf(
'<div class="site-logo no-lazy">
<a href="%1$s" title="%2$s" rel="home">
@brianleejackson
brianleejackson / author-bio-box.css
Last active March 8, 2021 04:37
Author bio box CSS. As seen on https://woorkup.com
/*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;
}
add_filter( 'generate_google_font_display', function() {
return 'swap';
} );