• Home
  • /
  • Blog
  • /
  • 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.


You may also like

Hostgator Review

Hostinger Review

Best Pre-workout Supplements

About the author 


Daniel Scocco is a programmer and entrepreneur located in São Paulo, Brazil. His first company, Online Profits, builds and manages websites in different niches. His second company, Kubic, specializes in developing mobile apps for the iOS and Android platforms.


    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.

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

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

  4. 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’??

  5. 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?

  6. 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!

  7. No joy here.

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

  8. 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!

  9. Hello,

    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!


  10. Daniel:

    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!

  11. 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.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}