WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The best thing I liked about the new v3.5 media manager was being able to insert images to a post hosted by an external site like photobucket using "Insert from URL". I normally format my image inserts manually and was hoping "Insert from URL" would reduce some of my work.

Unfortunately I can't add anything to the img src tag that is generated. Specifically I use the alignright class alot but this is ignored in the RSS feed so if I republish my blog post on a non-wordpress powered site the images aren't floated. I want to add an extra style="float:XXX" to the code that is sent to the editor to cover that issue.

If $align is 'right' then it outputs float:right and so on.

I am doing this as a personal plugin and I got it activated but it doesn't output anything when I use "Insert from URL"

I've searched all these help sites and really haven't found anything exactly as I need and my experience level with PHP and wordpress is kind of low (I understand the concepts but have trouble with the syntax)

The closest I got was this previous question: Need help building a filter to edit the output of “image_send_to_editor”

Here is the function I have so far and any hints or tips on what I am doing wrong will help me.

add_filter('image_send_to_editor', 'dlb_filter_fl',10,8);

function dlb_filter_fl ($html, $id, $caption, $title, $align, $url, $size, $alt) {

if ($align == 'right');
     $html = '<img src="' . $url .  '" class="' . $align . '" style="float:right" />';

return $html;

I could be using the wrong filter. I'm not sure. Right now the code is active and get no fatal errors but it doesn't add anything to my img scr tag.

share|improve this question

I can't find the proper hook, but there is alternative solution: to add style="float:right" to all images in content, which have class="alignright":

add_filter('the_content', 'my_add_image_float_right');

function my_add_image_float_right($content) {
    $pattern = '@(<img.+)(alignright)(.*)(/>)@Ui';
    $replacement = '$1$2$3 style="float:right" />';
    $content = preg_replace($pattern, $replacement, $content);
    return $content;
share|improve this answer
Thanks for the help. Not quite what I wanted to do but gives me something else to think about – Doug B. Feb 8 '13 at 3:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.