Last active
October 14, 2021 17:50
-
-
Save ideag/5055492 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'image_send_to_editor', 'tiny_force_caption', 100 ); | |
function tiny_force_caption( $html ) { | |
$a = strpos($html, 'caption'); | |
if ($a!=1) { | |
preg_match('/(alignnone|alignleft|alignright|aligncenter)/', $html,$c); | |
preg_match('/width="(\d*)"/', $html,$w); | |
preg_match('/alt="([^"]*)"/', $html,$m); | |
preg_match('/wp-image-(\d*)"/', $html,$n); | |
if (!isset($n[1])) $n[1] = '0'; | |
$html = '[caption id="attachment_'.$n[1].'" align="'.($c?$c[1]:'alignnone').'" width="'.$w[1].'"]'.$html." © ".get_bloginfo('title')."[/caption]"; | |
} | |
return $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment