Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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;
- }
Advertisement
Add Comment
Please, Sign In to add comment