]*)*>~Ui', $footer_script . '\\0', $buffer, 1 ); } else { // 'sync_head' $head_script = '' . ''; $buffer = preg_replace( '~
]*)*>~Ui',
'\\0' . $head_script,
$buffer,
1
);
$footer_script =
'';
$buffer = preg_replace(
'~]*)*>~Ui',
$footer_script . '\\0',
$buffer,
1
);
}
return $buffer;
}
/**
* Maps attachment URLs to their corresponding post IDs.
*
* Updates the internal posts-by-URL mapping for tracking purposes.
*
* @param string $url The attachment URL.
* @param int $post_id The post ID.
*
* @return string The unmodified attachment URL.
*/
public function wp_get_attachment_url( $url, $post_id ) {
$this->posts_by_url[ $url ] = $post_id;
return $url;
}
/**
* Adds hooks specific to MetaSlider plugin compatibility.
*
* Modifies MetaSlider content to work seamlessly with lazy loading.
*
* @return void
*/
private function metaslider_hooks() {
add_filter( 'metaslider_nivo_slider_get_html', array( $this, 'metaslider_nivo_slider_get_html' ) );
}
/**
* Filters MetaSlider HTML output for compatibility.
*
* Prevents lazy loading from interfering with MetaSlider's image loading
* by adding a `no-lazy` class to images.
*
* @param string $content The MetaSlider HTML content.
*
* @return string Modified HTML content.
*/
public function metaslider_nivo_slider_get_html( $content ) {
// nivo slider use "src" attr of tags to populate
// own image via JS, i.e. cant be replaced by lazyloading.
$content = preg_replace(
'~(\s+)(class=)([\"\'])(.*?)([\"\'])~',
'$1$2$3$4 no-lazy$5',
$content
);
return $content;
}
}