Advertisement
jan_dembowski

youtube-rel.php

Jul 11th, 2012
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: YouTube PrettyPhoto links
  4. Description: This will filter YoutTube links in posts to add rel="PrettyPhoto" to each link.
  5. Author: Jan Dembowski
  6. Version: 0.1
  7. Author URI: http://blog.dembowski.net/
  8.  
  9. */
  10.  
  11. add_filter( 'the_content' , 'mh_youtube_rel' , 50 );
  12.  
  13. function mh_youtube_rel( $content ) {
  14.  
  15. // Regex to put all YouTube links into an array
  16. $mh_url_regex = "/\<a\ href\=\"http\:\/\/.*youtube\.com\/.*\"/";
  17. preg_match_all( $mh_url_regex , $content, $mh_matches );
  18.  
  19. // Go through that array and add rel="PrettyPhoto" to all selected links
  20. for ( $mh_count = 0; $mh_count < count( $mh_matches[0] ); $mh_count++ )
  21.     {
  22.     $mh_old_url = $mh_matches[0][$mh_count];
  23.     $mh_new_url = substr_replace( $mh_matches[0][$mh_count] , '" rel="PrettyPhoto"' , -1 );
  24.     $content = str_replace( $mh_old_url  , $mh_new_url , $content );
  25.     }
  26.  
  27. return $content;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement