It took me a little longer than I wanted but this plugin may get you what you are looking for.
I filtered the_content
and looked for this match from the gallery output.
<a href="https://..."><img data-attachment-id=
And inserts a rel="prettyPhoto"
inside the end of that <a href="...">
Which I think accomplishes what you wanted to do. If I put the new rel=
in the wrong place then please let me know in this topic.
Using a plain text editor (notepad, notepad++, or TextWrangler are good) and take the below PHP code and paste it into wp-content/plugins/add-prettyphoto.php
on your WordPress installation.
Once that’s done visit your WordPress dashboard plugin menu and activate the PrettyPhoto for galleries
plugin.
If anything goes wrong then just delete that one new file wp-content/plugins/add-prettyphoto.php
you created and that will fix it.
https://pastebin.com/F5VRWFPH
<?php
/*
Plugin Name: PrettyPhoto for galleries
Description: This plugin adds rel="prettyPhoto" for galleries
Author: Jan Dembowski
*/
add_filter( 'the_content', 'mh_add_prettyphoto' , 15 );
function mh_add_prettyphoto( $text ) {
// RegEx to find the right <a href=...><img data-attachment-id=... and put that into an array
$mh_regex = "/<a href=\"(http|https):\/\/[a-zA-Z0-9-.\/\?=]+\"><img\ data-attachment-id=/";
// Use that RegEx and populate the hits into an array
preg_match_all( $mh_regex , $text , $mh_matches );
// If there's any hits then loop though those and replace those hits
for ( $mh_count = 0; $mh_count < count( $mh_matches[0] ); $mh_count++ )
{
$mh_old = $mh_matches[0][$mh_count];
$mh_new = str_replace( '><img data' , ' rel="prettyPhoto"><img data' , $mh_old );
$text = str_replace( $mh_old , $mh_new , $text );
}
// Return any substitutions
return $text;
}