Now I See Why the WordPress Image Align Feature Was Not Working


There is one WordPress feature that was introduced with version 2.5 that always made me curious: the image alignment feature of the “Add media” editor. Why? Because it never worked!

I knew that I was probably doing something wrong, but since I didn’t have time to find it out, I just kept choosing “none” as the alignment, and then I would manually insert the right, left or center alignment attribute on the image tag.

Then last week when I was submitting one of my themes for the WordPress Themes Directory I got a message saying that since version 2.5 WordPress themes were required to have the following code on their stylesheet:

img.centered {
display: block;
margin-left: auto;
margin-right: auto;

img.alignright {
padding: 4px;
margin: 0 0 2px 7px;
display: inline;

img.alignleft {
padding: 4px;
margin: 0 7px 2px 0;
display: inline;

.alignright {
float: right;

.alignleft {
float: left;

Duh! That is why the alignment feature was not working on my blogs, I never added that code! Now if you faced this problem in the past, now you know how to solve it.

Browse all articles on the WordPress category

78 Responses to “Now I See Why the WordPress Image Align Feature Was Not Working”

  • Pieter

    Thanks! Copied and pasted in the stylesheet and its working like a charm!

  • Jillian

    I’ve been working on a theme in editor for a while. It’s still not working for me.

  • Mark


    I bypassed the stylesheet (i.e. style.css) altogether and pasted the above code into my index.php file, right before the closing tag.

    Works now. Try that.

  • Mark

    Thanks for the fix! I was searching for why my image align wasn’t working and hit this post. Works perfectly.

  • Cecil

    Sorry, doesn’t work for me. Must be something wrong with something else in my code if it’s working for everyone else.

  • Mark

    Thanks a lot.. You saved me some frustration..

  • Dave Haygarth

    Oh I’ve been looking for this answer for AGES!!! I love you !!!

  • Netbooks RUS

    I just can not get the silly thing to align. There must be some other code we can use.

  • Rodrigo

    Very simple and powerfull, thanks!
    I was getting mad with the image alignment!

  • Borino

    Excellent. Thanks for the quick and simple fix.

  • Netbooks

    Also having the same issue…I have that code but it is not aligning

  • Mohit

    Where to place that code in blog stylesheet?

  • Tom

    Brilliant, thankyou so much!

  • gadget

    Thanks for the tip but upon checking, my code is exactly the same as that – but it’s not aligning correctly?!

  • David P

    May you live to be 1000 years old.

  • Dusibello

    Style.css is a long, complicated file. This code presumably should go in a certain section?

    One of the posts above says to put in ‘on the content section’??

  • Peter

    OK, I don’t get it. Pasted the code in to the css file, updated, checked the images and set the second one to the right and – damn, still the same. What is it I’m missing here?

  • Peter Butler

    Gee, I would ahve thought the new big upgrade to 2.7 would have sorted this

  • Clone High

    Thanks a ton, this is a life saver!

  • Tim


    This was driving me insane.

  • Sebastien Page

    Thank you for saving me a time. It’s been driving me nuts for an hour until I came across this post! Thanks

  • Stefan Wurz

    Yeah, really I like this article. Thanks for this nice article

  • Andy

    Fantastic! I thought I was going mad after the upgrade to 2.6 on my blog none of the image alignment worked for new images in posts.
    You have saved me bacon. Cheers!

  • Susan

    thank you!

  • Dusibello

    No joy here.

    Does the code need to be pasted into a certain section of the stylesheet file?

  • Tobias Goth

    Big Thanks! I was starting to think that my version of WordPress was bust, but you made me think other wise.

  • Saeed

    I have used this code to align my images perfectly on my blog. However, in the RSS feed reader, e.g. Google Reader, they still don’t float properly. Has anyone else been having the same problem as well? If so, were you able to rectify it? Please share kindly!

  • Avigail


    thank you for sharing. It works without any problems. I was driving me mad I thought that I can just use new wp themes, but just pasting the code into the stylesheet works!


  • BloggerNewbie


    big help! got any clues on the post at a future date feature? When I set a future date, the post goes out into never never land not to be seen ever again!

  • Kristen

    OH THANK YOU! I have been so frustrated with this topic and just adding that code to my stylesheet automatically fixed my images.


Comments are closed.