Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: YouTube PrettyPhoto links
- Description: This will filter YoutTube links in posts to add rel="PrettyPhoto" to each link.
- Author: Jan Dembowski
- Version: 0.1
- Author URI: http://blog.dembowski.net/
- */
- add_filter( 'the_content' , 'mh_youtube_rel' , 50 );
- function mh_youtube_rel( $content ) {
- // Regex to put all YouTube links into an array
- $mh_url_regex = "/\<a\ href\=\"http\:\/\/.*youtube\.com\/.*\"/";
- preg_match_all( $mh_url_regex , $content, $mh_matches );
- // Go through that array and add rel="PrettyPhoto" to all selected links
- for ( $mh_count = 0; $mh_count < count( $mh_matches[0] ); $mh_count++ )
- {
- $mh_old_url = $mh_matches[0][$mh_count];
- $mh_new_url = substr_replace( $mh_matches[0][$mh_count] , '" rel="PrettyPhoto"' , -1 );
- $content = str_replace( $mh_old_url , $mh_new_url , $content );
- }
- return $content;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement