Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brianleejackson/9a89a8027ab694ace275402ed3623657 to your computer and use it in GitHub Desktop.
Save brianleejackson/9a89a8027ab694ace275402ed3623657 to your computer and use it in GitHub Desktop.
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">
<img %3$s />
</a>
</div>',
esc_url(apply_filters('generate_logo_href', home_url('/'))),
esc_attr(apply_filters('generate_logo_title', get_bloginfo('name', 'display'))),
$html_attr
);
}
add_filter('generate_logo_output', 'wpd_generate_logo_output', 10, 3);
//add no-lazy class to mobile header logo
function wpd_generate_mobile_header_logo_output($output) {
//make sure we can get default settings
if(!function_exists('generate_menu_plus_get_defaults')) {
return $output;
}
//get settings args
$settings = wp_parse_args(
get_option('generate_menu_plus_settings', array()),
generate_menu_plus_get_defaults()
);
//logo output
return sprintf(
'<div class="site-logo mobile-header-logo">
<a href="%1$s" title="%2$s" rel="home">
<img src="%3$s" class="no-lazy" alt="%4$s" />
</a>
</div>',
esc_url(apply_filters('generate_logo_href' , home_url('/'))),
esc_attr(apply_filters('generate_logo_title', get_bloginfo('name', 'display'))),
esc_url(apply_filters('generate_mobile_header_logo', $settings['mobile_header_logo'])),
esc_attr(apply_filters('generate_logo_title', get_bloginfo('name', 'display')))
);
}
add_filter('generate_mobile_header_logo_output', 'wpd_generate_mobile_header_logo_output');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment