0

function add_prettyphoto_attributes_to_images($content) {
    // Add 'prettyphoto' class
 $pattern = '/<img\s+[^>]*src=(["\'])(.*?)\1[^>]*>/i';
 $new_content = preg_replace_callback($pattern, function($matches) {
  $img_tag = $matches[0];
  $src = $matches[2];
  $wrapped_img_tag = "<a href='$src' class='prettyphoto'>$img_tag</a>";
  return $wrapped_img_tag;
 }, $content);
    return $new_content;
}
add_filter('the_content', 'add_prettyphoto_attributes_to_images', 999999);
 function enqueue_prettyphoto_scripts() {
    // Enqueue PrettyPhoto JavaScript file
    wp_enqueue_script('prettyphoto-script', 'https://cdnjs.cloudflare.com/ajax/libs/prettyPhoto/3.1.6/js/jquery.prettyPhoto.min.js', array('jquery'), '3.1.6', true);
     // Enqueue PrettyPhoto CSS file
    wp_enqueue_style('prettyphoto-style', 'https://cdnjs.cloudflare.com/ajax/libs/prettyPhoto/3.1.6/css/prettyPhoto.min.css');
}
add_action('wp_enqueue_scripts', 'enqueue_prettyphoto_scripts');

Jagdish Sarma Asked question March 6, 2024
Add a Comment