Archived topic
Dispatch theme has Largest Contentful Paint
3 replies · Started by Wayne on April 14, 2021
How do i improve the Largest Contentful Paint for my site? I noticed on many speed test sites espeially google page speed insights that the largest contentful paint is pretty slow on mobile. Is there a way to fix this?
I'm optimizing the images and using a cdn and wprocket as much as I can but it is still pretty slow. How can I make this faster?
I provided the links in the private information down below. You'll notice that all of my posts have a slow load time.
Hi there,
try the method i provide here to load a smaller image size on mobile devices:
Also check the size of the original images - smaller images the better - the original images from the Dispatch import were not well optimized.
so the code is
add_action( 'wp_head', function(){
$featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'medium_large');
if ($featured_img_url) {
echo '
<style>
@media(max-width: 768px) {
.page-hero {
background-image: url(' . $featured_img_url . ');
}
}
</style>';
}
});
is that the code?
And how do i put it in my site?
Hi there,
Here's how to add PHP - https://docs.generatepress.com/article/adding-php/
So it's either use a child theme's functions.php,
or use Code Snippets plugin here - https://en-ca.wordpress.org/plugins/code-snippets/