preg_replace on image caption
-
I have the following code:
function send_media_credit_to_editor($html, $attachment_id, $attachment) { $post =& get_post($attachment_id); $author_id = $post->post_author; $user = get_userdata($author_id); if ( !empty($user->user_nicename) ) $author_nicename = $user->user_nicename; $pattern = '/(\"]<img)/i'; $author_link = '<a href="' . get_author_posts_url($author_id, $author_nicename) . '">$author_nicename</a>'; $replacement = '<br /><a href=' . $author_link . '${1}'; $html = preg_replace($pattern, $replacement, $html); return $html; } add_filter('image_send_to_editor', 'send_media_credit_to_editor', 10, 3);
However, the $html that I return is not used and the caption is not filtered at all. However, if I replace the entire function with:
function send_media_credit_to_editor($html, $attachment_id, $attachment) { $html = 'Hi'; return $html; }
Then the caption is properly changed to be simply the word “Hi”. Why is my preg_replace not working and how can I get it to work?
Thanks,
Scott
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘preg_replace on image caption’ is closed to new replies.