Article 6MQTM Error i am facing in wordpress

Error i am facing in wordpress

by
Bala451987
from LinuxQuestions.org on (#6MQTM)
Hello guys!

I am not sure, whether i can ask the question here about WordPress. I am trying to implement lazy-load function through code. But i am encountering an error. Please find the error and the code i am implementing down below.

## The code i am implementing in function.php

function add_lazyload_to_images($content) {
if (is_admin()) {
return $content;
}

// Add 'loading="lazy"' attribute to images
$content = preg_replace('/<img([^>]*)src=["\']([^"\']*)["\']([^>]*)>/i', '<img$1src="$2" loading="lazy"$3>', $content);

return $content;
}

// Apply the filter to 'the_content'
add_filter('the_content', 'add_lazyload_to_images');

## The error i am encountering:

PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'add_lazyload_to_images' not found or invalid function name in /home/kc8klqrq8k3y/public_html/blog.drugvigil.com/wp-includes/class-wp-hook.php on line 324

Can anyone understand and help me to find the solution. Thanks in advance.
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments