Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. <?php
  2.  
  3. function show_img_vars($html, $id, $caption, $title, $align, $url, $size, $alt) {
  4. // remove alignment class from the image
  5. $html = preg_replace( '/ class=".*"/', '', $html );
  6.  
  7. // return the normal html output you would expect
  8. $figure = "<figure class='image-inline";
  9. if ($align == 'left' | 'right') {
  10. $figure .= " align".$align;
  11. } elseif ($align == 'center') {
  12. $figure .= " aligncenter";
  13. }
  14. $figure .= "'>\n";
  15. $figure .= " $html\n";
  16. if ($caption) {
  17. $figure .= " <figcaption class='caption'>$caption</figcaption>\n";
  18. }
  19. $figure .= "</figure>\n";
  20.  
  21. return $figure;
  22. }
  23. add_filter( 'image_send_to_editor', 'show_img_vars', 10, 9 );
  24.  
  25. function filter_captions_to_editor($shcode, $html) {
  26. // the caption code strips the alignment class out of the html so...
  27. // we have to recover it from the shortcode like so
  28. $align = preg_replace('/(\[.*)align="(\w*)"(.*\])((<.*>)\s*)+(.*)(\[.*\])/', '\2', $shcode );
  29. // and insert it back into the html like so (P.S. I'm a total regex noob)
  30. $html = preg_replace('/<figure class=\'.*\'/', '<figure class=\'image-inline '.$align.'\'', $html);
  31.  
  32. return $html;
  33. }
  34. add_filter( 'image_add_caption_shortcode', 'filter_captions_to_editor', 10, 9);
  35.  
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement