Home
AGEMIX-060
// Thm vo functions.php
/**
* Add fetchpriority="high" to images above the fold based on device
* Desktop: ~20 images, Mobile: ~8-10 images
*/
function add_fetchpriority_to_poster($poster_html, $post_id = null) {
global $wp_query;
// Get current post index in the loop
$current_post_index = isset($wp_query->current_post) ? $wp_query->current_post : 0;
// Determine priority count based on device
if (wp_is_mobile()) {
$priority_limit = 9; // First 10 images for mobile (8-10 above fold)
} else {
$priority_limit = 19; // First 20 images for desktop (~20 above fold)
}
// Add fetchpriority="high" to images above the fold
if ($current_post_index <= $priority_limit && !empty($poster_html)) {
// Check if fetchpriority is already set
if (strpos($poster_html, 'fetchpriority') === false) {
$poster_html = str_replace('
current_post) ? $wp_query->current_post : 0;
// Get the original poster image
$data = new BCT_DataPost;
$poster = $data->poster($post_id);
// Determine priority based on device viewport
if (wp_is_mobile()) {
$should_prioritize = ($current_post_index <= 9); // Mobile: 10 images
} else {
$should_prioritize = ($current_post_index <= 19); // Desktop: 20 images
}
// Add fetchpriority for images above the fold
if ($should_prioritize && !empty($poster)) {
$poster = str_replace('