Preload on Page by Page Basis
-
Hello, some pages and ad landing pages on our site have “hero images.” We are currently preloading one image (the home page hero image), which is used on a few other landing pages also. However, we have some other hero images that are now being used. Preloading has shown a significant improvement in LCP on PageSpeed Insights, so I would like to preload the other hero images also, but not on every page of course.
I read the info on this topic: https://wordpress.org/support/topic/preload-just-on-one-a-specific-page/ which suggests using the following filter.
add_filter( 'autoptimize_filter_extra_tobepreloaded', 'frontpage_specific_preload' ); function frontpage_specific_preload( $preload_array ) { if ( is_front_page() ) { $preload_array[] = 'https://yoursite.com/wp-content/themes/yourtheme/tobepreloaded.file'; } return $preload_array; }I assume I would need to create multiple filters, one for each page I would like to preload an image on. My question is what will ‘frontpage_specific_preload’ and is_front_page become since I will be referencing different pages? Also, where exactly should this code be placed?
The topic ‘Preload on Page by Page Basis’ is closed to new replies.