Advertisement
brentini

Add thickbox to WordPress images and galleries -simple

Mar 3rd, 2012
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  1. <?php
  2. add_filter('the_content', 'brentini_addthickboxclass');
  3. function brentini_addthickboxclass($content) {
  4. add_thickbox();
  5.     $pattern[0] ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
  6.     $replacement[0] = '<a$1href=$2$3.$4$5 class="thickbox">';
  7.     $pattern[1]     = "/(<a href=)('|\")([^\>]*?)(\.bmp|\.gif|\.jpg|\.jpeg|\.png)('|\")([^\>]*?)(>)(.*?) title=('|\")(.*?)('|\")(.*?)(<\/a>)/i";
  8.     $replacement[1] = '$1$2$3$4$5$6 title=$9$10$11$7$8 title=$9$10$11$12$13';
  9.     $pattern[2]     = "/(<a href=)('|\")([^\>]*?)(\.bmp|\.gif|\.jpg|\.jpeg|\.png)('|\")([^\>]*?) title=([^\>]*?) title=([^\>]*?)(>)(.*?)(<\/a>)/i";
  10.     $replacement[2] = '$1$2$3$4$5$6 title=$7$9$10$11';
  11.     $content = preg_replace($pattern, $replacement, $content);
  12.     return $content;
  13. }
  14. function brentini_add_thickbox_class_to_head(){
  15. {?>
  16. <script type="text/javascript">jQuery(document).ready(function($){
  17.   $('dt.gallery-icon a').addClass('thickbox');
  18. });</script>
  19. <?php }}
  20. add_action('wp_head', 'brentini_add_thickbox_class_to_head');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement